繁体   English   中英

缺少自定义函数的参数2

[英]Missing argument 2 for a custom function

所以我试图在保存更改后用同一帖子的自定义字段替换原始的post_title。 但是,我在帖子页面上收到以下错误:

警告:第113行的$ PATH / public_html / wp-content / themes / $ THEME / functions.php中的wpse33385_filter_title()缺少参数2

// replaces the original post_title with the value of pac-short-title

add_filter( 'the_title', 'wpse33385_filter_title', 10, 2);

function wpse33385_filter_title( $title, $post_id )
{
    if( $new_title = types_get_field_meta_value( 'pac-short-title', $post_id ) )
    {
        return $new_title;
    }
    return $title;
}

我很困惑因为我在add_filter中定义了一些参数?

在某些版本的WordPress中,在某些使用此过滤器的情况下未设置post id可能导致此警告。

解决方案是为post id设置默认值。

function wpse33385_filter_title( $title, $post_id = null )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM