How to get post count including nested categories

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 .= 'lia 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.

Topic recursive taxonomy custom-taxonomy categories posts Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.