How to list empty categories too while listing sub categories

I’m trying to list sub categories of my parent category by using a function code and calling this code into template but while doing this I couldn’t list empty categories. Need your helps to do that.

Here is my function code

function sub_category_list(){

if(is_category()) {



$breakpoint = 0;

$thiscat = get_term( get_query_var('cat') , 'category' );

$subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );



if(empty($subcategories) && $thiscat->parent != 0) {

    $subcategories = get_terms( 'category' , 'parent='.$thiscat->parent.'' );

}



$items='';

if(!empty($subcategories)) {

    foreach($subcategories as $subcat) {

        if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';

        $items .= '

        <li class="cat-item cat-item-'.$subcat->term_id.$current.'">

            <a href="'.get_category_link( $subcat->term_id ).'" title="'.$subcat->description.'">'.$subcat->name.'</a>

        </li>';

    }

    echo "<ul>$items</ul>";

}

unset($subcategories,$subcat,$thiscat,$items);

}

}

Thanks for helps from now on.

Read more here: How to list empty categories too while listing sub categories

Leave a Reply

Your email address will not be published. Required fields are marked *