When grabbing the product id's from a category where the is_anchor attribute is set we get the complete collection. Including products from underlying categories.

Question: How can we get a list/array of product id's for any given category id that has the is_anchor attribute set - where the collection contains only the real products from that category only (and not also products from underlying categories)

This is what we have to date. But I am sure this is not the fastest method.

$category = new Varien_Object(array('id'=>$_cat));
$positions = Mage::getResourceModel('catalog/category')->getProductsPosition($category);
$includeIDs = array_keys($positions);

Reference: Array of product ids for a given category (respecting is_anchor)

  • this is so far the first way I have found to get products for a categoryid not in the current site's tree, too. it feels very diagonal but it works where 10 other things have failed...
    – iphigenie
    Commented Mar 1, 2018 at 8:15

2 Answers 2


I think the fastest way (performance) to get only an array containing the product ids for a category is to build your own query such as :

$resource = Mage::getResourceModel('core/resource');
$adapter = $resource->getReadConnection();
$product_ids = $adapter->fetchCol(
        ->where('category_id = ?', $cat)

I think the only alternative is to join catalog_category_product into the product collection

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.