Irphan
Irphan

Reputation: 41

Magento category filter by custom attributes

I have added custom attributes to categories in Magento, now I need to select categories with these attributes filter in the custom module. Can someone help me, please?

Upvotes: 1

Views: 6804

Answers (2)

Irphan
Irphan

Reputation: 41

Never mind,I got the solution.i just had to add below line of code and it worked

->addAttributeToFilter('door_material', 53)

where "door_material" is custom attribute for category and "53" is selected option id in back-end.I hope it will help someone.

Upvotes: 1

Marius
Marius

Reputation: 15216

$categories = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToFilter('attribute_code_here', 'value_here');
$categories->addAttributeToFilter('parent_id', 2);//if you want only children of a specific category
    foreach ($categories as $category){
        //do something with $category
    }

Upvotes: 3

Related Questions