使用这个wordpress函数有什么问题:wp\u list\u categories()

使用这个wordpress函数有什么问题:wp\u list\u categories(),wordpress,wp-list-categories,Wordpress,Wp List Categories,我看不出我在这件事上出了什么问题,请帮忙好吗 $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); //then set the args for wp_list_categories $args = array( 'child_of' => $current_term->term_id, 'taxonomy' => $curr

我看不出我在这件事上出了什么问题,请帮忙好吗

$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

//then set the args for wp_list_categories
 $args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 1,
    'title_li' => __(''),
    'echo' => '0'
    );

$terms_list = wp_list_categories( $args);
if( $terms_list ){
    ?>
    <div id="terms_list">
        <ol>
            <?php echo $terms_list; ?>
        </ol>
    </div>
    <?php
};

// this line is just here for debug to confirm that we have the right item  - it is not a part of the design or normal functionality
 echo  '<h1>terms_id: ' . $current_term->term_id . ' name: ' . $current_term->name . ' and: ' . $current_term->taxonomy . '</h1>'; 
?>
因此导致问题的函数是wp_list_categories,它根本不返回任何内容。我已经检查了这个词是否正确,它确实有帖子,它确实有孩子,他们也有帖子。感谢安迪的帮助

$current\u term->term\u id的类型为string。参数的子_需要一个整数

尝试这样做:

$args = array(
    'child_of' => (int) $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 1,
    'title_li' => __(''),
    'echo' => '0'
);

您是否尝试将Hierarchy更改为1而不是true?根据,默认情况下,它设置为true。我认为您需要添加if is set$terms\u list{也不需要;在if语句的结尾,@Howlin或Hareesh的建议都没有影响,谢谢大家。@Hareesh;是多余的,我同意,但没有影响。哦,有趣的@henrywright,我错过了那一个。不幸的是,即使按照你的建议进行打字,仍然没有输出。他没有必要打字re,$current\u term->term\u id已经是int类型。@ange008代码说明$current\u term->term\u id是string类型。如果代码错误,请告诉我,我会更新它。请看这里:@henrywright是的,在这种情况下它是错误的,执行var\u dump$current\u term->term\u id;返回int n。