Search code examples
wordpresscustom-post-typetaxonomy

List Categories of Custom Post Type without Category child


I have Created post_type=ug-dept and taxonomy=dept. Under the dept Taxonomy created some category and Subcategory. Added Post into that.

Now on listing Subcategory also Listed.

<ul>
  <?php wp_list_categories('taxonomy=dept&orderby=id&title_li=&include_children=false');?>
</ul>

How to Remove Child on Category Listing. Please don't give a solution like: 'exclude' => '12,13' By this every time i need to add.

Why "include_children=false" not working ?


Solution

  • $cat_args = array(
        'taxonomy' => 'dept',
        'orderby' => 'id',
        'order' => 'ASC',
        'parent' => 0,
    );
    $cat_data = get_categories( $cat_args ); 
    
    foreach ( $cat_data as $cat ) {
          echo $cat->name;
    }
    

    It will help you