Forum
Filter blog by multiple categories
On my product detail page I would like to filter out some blog posts by case study, and by segment that matches the product.
I have created a category set called Segments
So my post.html & products.html template have the following
<perch:categories id="segments" set="segments" label="Segments" display-as="checkboxes" suppress="true" divider-before="Choose your segment">
<perch:category id="catSlug" type="slug" />
<perch:category id="catTitle" type="text" />
</perch:categories>
I have another set called en-eu
which has a category called case-studies
So I currently have them filtering like this
$productsegment = perch_collection('products', [
'filter' => 'slug',
'value' => perch_get('s'),
'category-match' => 'all',
'category' => 'segments/'.perch_get('cat'),
'template' => 'products/_product_segment.html',
], true);
$fullsegmenturl = 'segments/'.$productsegment;
// Strips out all whitespace
$stripout = preg_replace('/\s+/', '', $fullsegmenturl);
perch_blog_custom(array(
'category' => array("en-eu/case-studies", $stripout),
'category-match' => 'all',
'count' => 3,
'template' => 'casestudy_image.html',
'sort' => 'postDateTime',
'sort-order' => 'DESC',
'blog' => 'en-eu',
));
This works but only if there is one category selected on the product page. I need to get it working if the editor selects multiple categories.
Any ideas?
Thanks
Do you need
'category-match' => 'any',
instead?