最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom taxonomy - Get children of taxonomies

programmeradmin0浏览0评论
    $terms = get_terms([
        'taxonomy' => array('Movies, Musics, Books, Games'),
        'parent' => 0,
        'depth'=> 2,
        'hide_empty' => false,
    ]);
    $sorted_terms = [];
    if ( $terms ) {
        foreach ( $terms as $term ) {
            $sorted_term = [
                'WP_Term'            => $term, // the global term
                'icon'               => get_field( 'logo', $term->taxonomy . '_' . $term->term_id ),
                'srating'               => get_field( 'rating', $term->taxonomy . '_' . $term->term_id ),
                'carrentActiveClass' => '',
                'count'              => (int) wpse340250_term_count( $term, 'sikayet' ),
                // everything you will need later here
            ];
///// and my code continue

in the above code I can get terms of different taxonomies. But I am trying to get children of taxonomy terms. Can any one help me please

'parent' => 0,
        'depth'=> 2,

did not work

    $terms = get_terms([
        'taxonomy' => array('Movies, Musics, Books, Games'),
        'parent' => 0,
        'depth'=> 2,
        'hide_empty' => false,
    ]);
    $sorted_terms = [];
    if ( $terms ) {
        foreach ( $terms as $term ) {
            $sorted_term = [
                'WP_Term'            => $term, // the global term
                'icon'               => get_field( 'logo', $term->taxonomy . '_' . $term->term_id ),
                'srating'               => get_field( 'rating', $term->taxonomy . '_' . $term->term_id ),
                'carrentActiveClass' => '',
                'count'              => (int) wpse340250_term_count( $term, 'sikayet' ),
                // everything you will need later here
            ];
///// and my code continue

in the above code I can get terms of different taxonomies. But I am trying to get children of taxonomy terms. Can any one help me please

'parent' => 0,
        'depth'=> 2,

did not work

Share Improve this question edited Jan 22, 2021 at 16:24 Gidromasservis QSC asked Jan 22, 2021 at 16:18 Gidromasservis QSCGidromasservis QSC 331 silver badge10 bronze badges 3
  • By setting 'parent' => 0, you are querying for the top-level taxonomies. – Sharif Mohammad Eunus Commented Jan 22, 2021 at 16:32
  • when i change 0 to 1 , it doesnt show anything – Gidromasservis QSC Commented Jan 22, 2021 at 16:36
  • wooow I uderstant now, 'parent' => parent ID . thank you vey much Sharif Mohammad Eunus – Gidromasservis QSC Commented Jan 22, 2021 at 16:38
Add a comment  | 

1 Answer 1

Reset to default 0

not actually sure what you are trying to achieve with the code. I would write something like this to get the child terms

 $terms = get_terms([
        'taxonomy' => array('Movies, Musics, Books, Games'),
        'parent' => 0,
        'hide_empty' => false,
 ]);

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {

    foreach ($terms as $term) {

        $child_term =  get_term_children( $term->term_id, $term->taxonomy )

         //your code here
    }

}
发布评论

评论列表(0)

  1. 暂无评论