Props to Sally for improving on this to show post count
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => false
) );
if ( $children ) {
foreach( $children as $subcat )
{
echo '<li><a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . // wrapped
$subcat->name . ' (' . $subcat->count . ')' . '</a></li>';
}
}
UPDATE
To show the posts count:
As pointed in the comment, and based on the above code, you can use $subcat->count
to display the number of posts in the specific term.
Therefore I replaced the $subcat->name . '</a></li>'
with:
$subcat->name . ' (' . $subcat->count . ')' . '</a></li>'
which outputs something like: Term Name (1)
, Another Term Name (0)
, etc.
For the original code in question (using wp_list_categories()
), here’s how to fix it, and the fixed code:
-
Replace the
is_category()
withis_tax( 'p_scales' )
. -
Replace the
get_query_var( 'cat' )
withget_queried_object_id()
.if (is_tax('p_scales')) { $cur_cat = get_queried_object_id(); if ($cur_cat) { $new_cats = wp_list_categories('show_option_none=&echo=false&child_of=" . // wrapped $cur_cat . "&depth=1&title_li=&show_count=1&hide_empty=1&taxonomy=p_scales'); echo '' . $new_cats . ''; } }