I am retrieving a product collection and filtering the list by category.

I have just had to add some sub categories to one of them and now the products in the sub-categories are appearing in the collection for the parent category and I cannot work out how to only show products directly assigned to the parent category.

Here is an example of the code:

$cat = Mage::getModel("[custom-namepace]/Categories"); //this just extends the native Categories model
$cat->load($catId);  //some number
$products = Mage::getResourceModel("catalog/product_collection")

I am unable to add a filter on category_id as that causes an error. I have tried:






These all throw a fatal error like.

Fatal error: Call to a member function getBackend() on a non-object in [...]\app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 816

Any pointers on how to avoid picking up products in child categories?


I have now also tried to get the products list through the category and I still get products from the child categories.

$products = $cat->getProductCollection()
  • Well I'm pretty this would only work for native category models. As you're using a adamequip_aepage/Categories model I doubt it'll work. Commented Jul 15, 2016 at 10:36
  • well it gets the products fine when a category has no children - the custom (now removed project reference, perhaps you could, thanks) Categories model just extends the native category model Commented Jul 15, 2016 at 10:46
  • I have modifed my code to use directly the native catalog/category model and the problem still occurs - the product collection still contains products from the child categories Commented Jul 15, 2016 at 10:54

1 Answer 1


you could do something like this:

$collection = Mage::getResourceModel('catalog/product_collection')
    'product_id = entity_id',
->addFieldToFilter('category_id', 3);

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.