I'm hoping someone can help as I have searched and cannot find an answer...
I am using a loop in a shortcode to display a list of related items and I'm having trouble working out the logic of selecting multiple categories in an AND parameter.
For example, I have a category structure like this:
Products (id: 1)
Prod A (id: 2)
Prod B (id: 3)
Services (id: 4)
Service A (id: 5)
Service B (id: 6)
Overview (id: 7)
What I would like to do is show all posts that are categorised as id 7 AND specific other IDs.
For example:
'category__and' => array(7,2),
AND
'category__and' => array(7,5),
Which would show 2 results - posts categorised as (Overview AND Prod A) AND (Overview AND Service A).
Everything works if I only want to show one selection (eg. Overview AND Prod A) but I can't work out how to show multiples.
Changing it to category__in does not work because that shows all posts categorised as Overview including Prod B and Service B, in the above example. It's also not practical to use category__not_in to exclude categories because the list is quite long and will change (unless there's a way of programmatically working out which categories to exclude?).
Is there a way of using multiple pairs of category__and values, or a way of coding multiple loops for WP_Query to achieve this?
I hope that gives you enough to go on. Thanks in advance!