0

Is it possible to show all child/sub categories of all parent cats? I have the following hierarchy:

Parent Cat/Tax
-- Sub 1
-- Sub 2
Parent Cat/Tax 2
-- Sub 1
-- Sub 2

I would like to be able to show all the child categories on one template without the parent showing as well. Is that possible?

1

To exclude parent categories from your term list, you can just pass over them after you have retrieved your term list with get_terms

Example:

<?php
$args = array(
  'orderby' => 'name',
  );
$terms = get_terms( 'mytaxname', $args );
 if ( !empty( $terms ) && !is_wp_error( $terms ) ){
    foreach ( $terms as $term ) {

        if( 0 == $term->parent )
            continue;

        echo '<a href="' . get_category_link( $term ) . '">' . $term->name . '</a><br/>';
    } 
}
?>
0

Well, I actually figured a way out. I don't have many parent categories so I added the following 'exclude' command and removed the 'parent' command. I will be adding more ID's to cover my parent categories.

<?php

        $libargs=array(  
            'hide_empty'        => 0,  
            'exclude'           => array(16), //* Enter ID's of parent categories to exclude from list
            'taxonomy'      => 'mytaxname');  

        ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.