Excluding child products from category that is anchor through code/filter

Hi we have a category with a complex filter set-up: it shows 43 products in backend. When we grab the collection however and show it on the frontend it shows 52 products. I understand this is because we enable anchor = yes because it needs to be layered.

My question now is: how can we filter out the child products of our collection?

Our current collection call in template file: $_productCollection=$this->getLoadedProductCollection();

I have read some semi-similar questions, but none with a concrete results. I was thinking along the lines of adding a filter like this $_productCollection=$this->getLoadedProductCollection()->addAttributeToSelect('is_anchor'); or maybe this $this->_productLimitationFilters['category_is_anchor'] = 1; or maybe this $category->setIsAnchor(true); or maybe when looping over the products collection? (Add a continue statement)

Another solution would be if I can retrieve all the "genuine" product ids of the parent category (so this time without children) I can then merge exclude the ID's? Or do this is the foreach loop?

1 Answer 1


Do you want to filter this only on this category or on every?

I would go another way: The products are filtered by the product_category index.

I think it is better to change the index builder and implement the filter there. So you only have the products in the category that you want.

If you want it more fancy, you can extend the category with a new attribute to set whether you want the default or the "no anchor products" behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.