Home › Forums › General Issues › filter relationship query – exclude if a certain category › Reply To: filter relationship query – exclude if a certain category
If I understand you want to include posts that are in 2 categories but exclude them if they are also in a third category.
I.E. Show if in category 76 but not if it is also in category 78.
I think that in order to do this you need to use a tax_query. I could be wrong but I do not think the ‘cat’ argument can be used the way you are trying to use it and I also thing that using ‘category__in’ combined with ‘category__not_in’ will work the same way. Like I said, I could be wrong but I think these arguments work as ‘OR’ (meaning category 76 OR not category 78).
$args['tax_query'] = array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'term_id'
'terms' => array(76, 77),
'operator' => 'IN'
),
array(
'taxonomy' => 'category',
'field' => 'term_id'
'terms' => array(78),
'operator' => 'NOT IN'
)
);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.