I know I can use something like this to count for ONE tax:
$catcount=get_term_by('slug','apple', 'FRUIT');
echo $catcount->count;
but not sure how to count posts that are in combos between taxonomies...
I have two custom taxonomies, and I want to count the number of posts (custom post types, actually) that are in each pair match between them. So for example:
TAXONOMY ONE:
- rock
- paper
- scissors
TAXONOMY FRUIT:
- apple
- banana
- strawberry
And I want to query the taxonomies and return results for a count of:
- number of posts that are in rock and apple
- number of posts that are in rock and banana
- number of posts that are in rock and strawberry
- number of posts that are in paper and apple
- number of posts that are in paper and banana
- number of posts that are in paper and strawberry
- number of posts that are in scissors and apple
- number of posts that are in scissors and banana
- number of posts that are in scissors and strawberry
Is this something I need to use SQL for, or is there a good WP way to get at these counts?
tax_query
, it accepts multiple queries (as arrays with relationAND
orOR
),get_term_by
,get_term_children
, this answer ..