Home » Magento tutorials » How to Filter product collection by multiple categories in Magento

How to Filter product collection by multiple categories in Magento

In this tutorial, we will go through how to filter a product collection by multiple categories in Magento.

Filter by only 1 category

Magento offers a type of filter that can be used directly from the collection:

Filter by 2 or more categories

This is a completely different story. It’s very important to proceed correctly in order to avoid errors of the type:
[blockquote]Item (Mage_Catalog_Model_Product) with the same id already exist[/blockquote]

Proceed in the following way:

1. Call your collection and filter by the attributes you want to filter (all but the category one). For example:

2. After doing this, you can apply your multiple category filter as follows:
Important: do it in this order if you don’t want to face weird Magento issues.

About Gareth

avatar
Gareth is an editor at Tutorial Magento. His special hobby is to share magento knowledge and experience with everyone.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top