I'm trying to create a nested tax query that does the following:
- Exclude posts that have any of several specified category IDs.
- AND include posts that have any of several other specified category IDs, OR posts that have any of several specified tag IDs.
Here's what I've tried:
$args['tax_query'] = array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $omit_category_ids,
'operator' => 'NOT IN',
),
array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $category_ids,
'operator' => 'IN',
),
array(
'taxonomy' => 'post_tag',
'field' => 'term_id',
'terms' => $term_ids,
'operator' => 'IN',
),
),
);
This doesn't limit posts to only the categories I want, and it also sometimes has posts in the categories I want to omit.
When I remove the nesting, and instead use this:
$args['tax_query'] = array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $category_ids,
),
array(
'taxonomy' => 'post_tag',
'field' => 'term_id',
'terms' => $term_ids,
),
);
It works, but of course it does not exclude the categories I need to exclude.
Is what I need to achieve possible with WP_Query, or do I need a filter?