在模式调试中,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;
你能帮我吗?
答案 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;
}