I'm using this code to show a list of product child-categories of a specific category (Parent ID = 173) on my sidebar on a single product page.

    $orderby = 'name';
    $order = 'asc';
    $hide_empty = false ;
    $cat_args = array(
                'parent'     => 173,
                'orderby'    => $orderby,
        'order'      => $order,
        'hide_empty' => $hide_empty,

    $product_categories = get_terms( 'product_cat', $cat_args );
    if( !empty($product_categories) ){
        echo '<ul>';
        foreach ($product_categories as $key => $category) {
            echo '<li>';
            echo '<a href="'.get_term_link($category).'" >';
            echo $category->name;
            echo '</a>';
            echo '<li>';
        echo '</ul>';

However it's showing ALL child-categories that exist on my website. I would like to just show the active ones that this product is in. How can I tweak this to just show the active ones?

1 Answer 1


Most importantly - hide_empty => true Look in the codex for possible args for get_terms: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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