Wordpress: How to add the OR operator to this query?
I have this piece of code to count the number of posts in a custom taxonomy term and its child terms:
function wp_get_postcount($id) { $count = 0; $taxonomy = 'productcategories'; $args = array( 'child_of' => $id ); $tax_terms = get_terms($taxonomy,$args); var_dump($tax_terms); foreach ($tax_terms as $tax_term) { $count +=$tax_term->count; } return $count; }
The problem is, it returns as a null for the actual term that contains the post, because that has no child terms. I'd like to know if its possible for the query to include the term with the $id and its children as well?
Thank you!
Answers
Why not use 'pad_counts' in get_terms.
$terms=get_terms('my_taxonomy',array('pad_counts'=>1));