从PHP7.4更新到PHP8之后,我的error_log现在满是来自我正在使用的子主题的类似行:
PHP警告:试图在第181行的./public_html/wp-content/themes/themename-child/functions.php中读取bool上的属性"term_id“
下面是抛出错误的块。它用于修改分页,以便不导航特定类型(链接)的帖子。
// modify pagination to exclude post_format of 'link' on news/blog posts
function profound_navigation() {
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
}
$link_term = get_term_by('slug' , 'post-format-link' , 'post_format');
$quote_term = get_term_by('slug' , 'post-format-quote' , 'post-format');
the_post_navigation(
array(
'next_text' => 'Next Article %title',
'prev_text' => ' Previous Article%title',
// 'taxonomy' => 'post_format',
'excluded_terms' => array($link_term->term_id, $quote_term->term_id, 156),
)
);
}看起来这段代码仍然工作正常,但是如何修改这段代码以避免填充错误日志呢?
发布于 2021-10-18 01:42:56
确保您的分类法是存在的。哪个是post-format和post_format之间正确的分类段塞?
如果不存在$taxonomy或没有找到$term,则为False。
请参阅:https://developer.wordpress.org/reference/functions/get_术语_按/#返回
https://wordpress.stackexchange.com/questions/397004
复制相似问题