I have a lot of products that are part of disabled categories. Is there a way for me to delete them all?

I want to tell it the ID of the category and then delete all the products under that category.

Is this possible?

Thank you very much!

  • delete products or unassign products from the category ? Commented Jul 19, 2016 at 14:47
  • delete products!
    – PET
    Commented Jul 19, 2016 at 14:59
  • check my updated answer which deletes products permanently from magento of disabled categories Commented Jul 19, 2016 at 15:10
  • Worked for you ? Commented Jul 19, 2016 at 16:22
  • I will try it tonight.
    – PET
    Commented Jul 20, 2016 at 8:13

2 Answers 2


Replace @categoryId = 5 with your category id.

SET @categoryId = 5;  
DELETE FROM `catalog_product_entity` 
where `entity_id` IN 
 (select `product_id` from `catalog_category_product`
where `category_id` = @categoryId);

Note: Take backup first before hitting any direct query on DB.


to delete permanently products of disable categories use following code:-


$category_id = 45;
$products_collection = Mage::getModel('catalog/category')->load($category_id)->getProductCollection();

foreach($products_collection as $product){
    }catch(Exception $e){
        Mage::log("Unable to delete product with ID: ".$product->getId().");

Note:- If your product which is under disabled category as well as enabled category then product as product is getting deleted the product will be gone from the enable category as well

  • Thank you Pradeep for the answer. It's easier for me to delete this using SQL and not a PHP file... so I have to chose the other answer... However, is there a way to automatically search for all disabled categories and then delete the products from those categories? This category_id thing is great, but I do have a lot of categories. Thank You
    – PET
    Commented Jul 20, 2016 at 19:17

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.