WP_Query – using category__and when one of the categories is 0
Question
I am passing a variable $category
to category__and
, and it works unless $category = 0;
'category__and' => array(4) // works
'category__and' => array($category, 4) // works if category > 1
'category__and' => array(0, 4) // does not work.
I originally tried to just use cat
, but if the post has cat 4 and NOT cat 6, it will still show it. This is why I went to category__and.
'cat' => '4,6' // will show a post with category 4 even if 6 isn't present
I could write a conditional to check the value of $category
but that seems unnecessary and I think I’m overlooking something.
0
categories, wp-query
3 years
2020-04-05T08:51:01-05:00
2020-04-05T08:51:01-05:00 0 Answers
85 views
0
Leave an answer