A custom function which will return total post counts from the specified category and its child categories.
function wp_get_cat_postcount($id) { $cat = get_category($id); $count = (int) $cat->count; $taxonomy = 'category'; $args = array( 'child_of' => $id, ); $tax_terms = get_terms($taxonomy,$args); foreach ($tax_terms as $tax_term) { $count +=$tax_term->count; } return $count;}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.