Sep 13, 2012
kalpesh

Magento: Get category object from category name

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.

1
2
$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:

1
$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.

4 Comments

  • Now I know how to get category object from category name in magento. I appreciate your idea of sharing this, thanks!

  • thanks u for the help

  • Amazing code. Thank you so much.

  • It helps! =)

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions