admin管理员组文章数量:1278883
Since updating from PHP 7.4 to PHP 8, my error_log
is now full of lines like this from a child theme I'm using:
[17-Oct-2021 13:30:38 UTC] PHP Warning: Attempt to read property "term_id" on bool in ./public_html/wp-content/themes/themename-child/functions.php on line 181
Here is the block that is throwing the error. It was used to modify the pagination so posts of a particular type (links) are not navigated.
// 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' => '<span class="meta-nav">Next Article <i class="flaticon-right-arrow"></i></span><h3 class="title">%title</h3>',
'prev_text' => '<span class="meta-nav"><i class="flaticon-left-arrow-1"></i> Previous Article</span><h3 class="title">%title</h3>',
// 'taxonomy' => 'post_format',
'excluded_terms' => array($link_term->term_id, $quote_term->term_id, 156),
)
);
}
Seems like the code still works fine, but how do I modify this code to avoid filling up my error log?
Since updating from PHP 7.4 to PHP 8, my error_log
is now full of lines like this from a child theme I'm using:
[17-Oct-2021 13:30:38 UTC] PHP Warning: Attempt to read property "term_id" on bool in ./public_html/wp-content/themes/themename-child/functions.php on line 181
Here is the block that is throwing the error. It was used to modify the pagination so posts of a particular type (links) are not navigated.
// 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' => '<span class="meta-nav">Next Article <i class="flaticon-right-arrow"></i></span><h3 class="title">%title</h3>',
'prev_text' => '<span class="meta-nav"><i class="flaticon-left-arrow-1"></i> Previous Article</span><h3 class="title">%title</h3>',
// 'taxonomy' => 'post_format',
'excluded_terms' => array($link_term->term_id, $quote_term->term_id, 156),
)
);
}
Seems like the code still works fine, but how do I modify this code to avoid filling up my error log?
Share Improve this question edited Oct 17, 2021 at 23:46 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Oct 17, 2021 at 14:28 algalgalgalg 1151 gold badge1 silver badge4 bronze badges 2 |1 Answer
Reset to default 1Make sure your taxonomy is exist. Which is a correct taxonomy slug between post-format
and post_format
?
False if $taxonomy does not exist or $term was not found.
Please see: https://developer.wordpress/reference/functions/get_term_by/#return
本文标签: termsPHP Warning Attempt to read property quottermidquot on bool
版权声明:本文标题:terms - PHP Warning: Attempt to read property "term_id" on bool 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741266197a2368511.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
post_format
andpost-format
when usingget_term_by
, is this intentional? one with dash symbol and one with underscore. This could be the issue. Do aprint_r
on$link_term
and$quote_term
to see what they return, one is 100% empty. – Buttered_Toast Commented Oct 17, 2021 at 14:40post-format
was empty and should've beenpost_format
. Thanks! – algalg Commented Oct 18, 2021 at 15:29