Forum
Filter Collection by category catSlug
I have a collection and have included categories that it can be tagged with. I want to be able to filter by these categories but can't seem to get it working. My code is:
<perch:categories id="categories" label="Categories" set="Recipes" order="7">
<perch:before>
<aside class="related-categories">
<h3>
Categories
</h3>
<ul>
</perch:before>
<li>
<a href="/recipes?cat=<perch:category id="catSlug" />" rel="tag" itemprop="recipeCategory">
<perch:category id="catTitle" />
</a>
</li>
<perch:after>
</ul>
</aside>
</perch:after>
</perch:categories>
and then on the collection page I am doing:
perch_collection('Recipes', [
'filter' => 'categories',
'match' => 'eq',
'value' => perch_get('cat'),
]);
This results in no collection being matched. Could you tell me where I am going wrong with this? I tried filtering by categories[catSlug] also but seem to be clutching at straws with that!
Thanks
Use the dedicated
category
option to filter by category:Oh dear what a fool of me! I couldn't find that on the collection docs but have now found it in its dedicated section.
Thanks