I have been stuck on a particular problem for a while now and have yet to find a way around it. I have custom widgets and for each widget I have added the ability to filter posts based on category AND/OR tags (this functionality works). I am now trying to expand on that by including in each widget a custom field where you can enter the ID of a category you wish to exclude (the custom field is already in the widget and stores user input).
Let me show you what I have so far to help understand:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $num_posts,
'cat' => -5,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $category,
),
array(
'taxonomy' => 'post_tag',
'field' => 'id',
'terms' => $tags
),
),
'offset' => 1,
);
As you can see I am taking in two arrays of input for both $category and $tags (this is working fine), but what does not seem to be working is:
'cat' => -5,
If I remove the tax_query array completely, the exclude category works perfectly fine, so it appears that tax_query is overriding the exclude?
If someone could point me in the right direct, that would be great 🙂
Thanks!