This is potentially a bug* – but it doesn’t seem like it is the same one you have linked to. The problem lies in the get_terms
function. Specifically here: http://core.trac.wordpress.org/browser/trunk/wp-includes/taxonomy.php#L1397
The array of terms (which when parent=0
, are are just the top level terms) gets passed to _pad_term_counts
which says:
Add count of children to parent count.
Recalculates term counts by including items from child terms. Assumes all
relevant children are already in the $terms argument
So the _pad_term_counts
function does its job properly, but its only ever given the top level terms and so only counts the posts in those terms, and not any child terms.
A work-around (this is not particular efficient), is to get all categories and then filter out all but the top level ones. Then has far as get_categories
(and so get_terms
) is concerned – you are after all terms and so all get counted:
//The args. Don't set parent
$args = array(
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'category',
'pad_counts' => 1
);
//I'll leave it to you to check for error objects etc.
$categories = get_categories($args));
$categories = wp_list_filter($categories,array('parent'=>0));
* Or maybe not: it is simply excluding the count of terms which do not match the criteria.