首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP警告:尝试读取bool上的属性"term_id“

PHP警告:尝试读取bool上的属性"term_id“
EN

WordPress Development用户
提问于 2021-10-17 14:28:08
回答 1查看 6.8K关注 0票数 1

从PHP7.4更新到PHP8之后,我的error_log现在满是来自我正在使用的子主题的类似行:

PHP警告:试图在第181行的./public_html/wp-content/themes/themename-child/functions.php中读取bool上的属性"term_id“

下面是抛出错误的块。它用于修改分页,以便不导航特定类型(链接)的帖子。

代码语言:javascript
复制
// 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),
            )
    );
}

看起来这段代码仍然工作正常,但是如何修改这段代码以避免填充错误日志呢?

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2021-10-18 01:42:56

确保您的分类法是存在的。哪个是post-formatpost_format之间正确的分类段塞?

如果不存在$taxonomy或没有找到$term,则为False。

请参阅:https://developer.wordpress.org/reference/functions/get_术语_按/#返回

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/397004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档