Forum
Category filtering with multiple `all` / `any`
Referencing the docs example of tshirts, is it possible to do something a bit more complex?
Like show tshirts in a preferred color (for example red, black and green), but they also need to match a polo neck or collar style?
I've tried to describe what I'd like in code below
perch_content_custom('T-shirts', array(
'category' => array('color/red', 'color/black', 'color/green') AND array('style/polo', 'style/collar')
));
This previous question seems to ask the same thing but the answer was not posted: https://forum.grabaperch.com/forum/11-02-2015-complex-category-filtering
You can match by AND or OR, not both.
OK, I eventually managed to figure this out using a similar solution to Paul here — https://forum.grabaperch.com/forum/11-02-2015-complex-category-filtering
… basically by assigning two different
perch_collection
calls to variables then usingarray_uintersect
in PHP to find the same values in both arrays.I'd dump my code here but it's very specific to the site I'm working on—if anyone else has trouble with this hit me up on the Perch Slack channel.