I am traversing through categories using function like this
function hierarchical_term_tree($category = 0)
{
$r = '';
$args = array(
'parent' => $category,
);
$next = get_terms('product_cat', $args);
if ($next) {
$r .= '<ul>';
foreach ($next as $cat) {
$r .= '<li><a href="' . get_term_link($cat->slug, $cat->taxonomy) . '" title="' . sprintf(__("View all products in %s"), $cat->name) . '" ' . '>' . $cat->name . ' (' . $cat->count . ')' . '</a>';
$r .= $cat->term_id !== 0 ? hierarchical_term_tree($cat->term_id) : null;
}
$r .= '</li>';
$r .= '</ul>';
}
return $r;
}
Thanks to deadlyhifi
But by default $cat->count
includes only direct post count, but I need to get post count including nested categories. (Sum of all nested + current)
Is there any way to get such count
value using wordpress functions and queries or I should implement this by myself ?
Thanks.
categories
widget show count including nested categories I have just looked through the implementation they are usingwp_list_categories