因此,我尝试在保存更改后将原始的 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 中使用此过滤器的某些情况下未设置帖子 ID 导致的。
解决方案是为帖子 ID 设置默认值。
function wpse33385_filter_title( $title, $post_id = null )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)