Magento: Get category object from category name

· kalpesh

Although this is very weird, to get category object (id, entity_type_id, attribute_set_id, children, etc.) from category name, sometimes it may be useful. Below lines of code will help you in getting it.

$cat = Mage::getResourceModel(‘catalog/category_collection’)->addFieldToFilter(‘name’, ‘Category_Name_Here’);  
print_r($cat->getData());

To get the category id from $cat object, simply use:

$cat->getFirstItem()->getEntityId();
Beware, the name should only return one category else the above query will return first category id no matter how many categories are retrieved.

#get categories from attribute set #get category object from name #magento category object