We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

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: http://forum.grabaperch.com/forum/11-02-2015-complex-category-filtering

Jay George

Jay George 2 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can match by AND or OR, not both.

OK, I eventually managed to figure this out using a similar solution to Paul here — http://forum.grabaperch.com/forum/11-02-2015-complex-category-filtering

… basically by assigning two different perch_collection calls to variables then using array_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.