所以我试图在保存更改后用同一帖子的自定义字段替换原始的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;
}
Run Code Online (Sandbox Code Playgroud)
我很困惑因为我在add_filter中定义了一些参数?
在某些版本的WordPress中,在某些使用此过滤器的情况下未设置post id可能导致此警告.
解决方案是为post id设置默认值.
function wpse33385_filter_title( $title, $post_id = null )
Run Code Online (Sandbox Code Playgroud)