wordpress PHP注意:尝试在3961行的..wp-includes / taxonomy.php中获取非对象的属性

时间:2018-03-17 08:31:17

标签: php wordpress

在模式调试中,error_log显示此错误:

  

PHP注意:尝试在第3961行的../public_html/wp-includes/taxonomy.php中获取非对象的属性

这是我的taxonomy.php文件:(与原始WordPress相同)

if ( $t->rewrite['hierarchical'] ) {
    $hierarchical_slugs = array();
    $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' );
    foreach ( (array)$ancestors as $ancestor ) {
        $ancestor_term = get_term($ancestor, $taxonomy);
        $hierarchical_slugs[] = $ancestor_term->slug;
    }
    $hierarchical_slugs = array_reverse($hierarchical_slugs);
    $hierarchical_slugs[] = $slug;
    $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
} else {

...

第3961行是:

$hierarchical_slugs[] = $ancestor_term->slug;

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

这意味着get_term($ancestor, $taxonomy);没有返回任期。 get_term可以返回null或WP_Error。

你可以在第3961行之前var_dump($ancestor_term);

理想情况下,您可以将该行包装在if条件中:

if(isset($ancestor_term->slug)){
    $hierarchical_slugs[] = $ancestor_term->slug;
}