How to get category using url_key and parent category_id? If category structure is as follows


Then using following code if try to load iOs category using url_key it load always load root->Mobile->iOS

$category = Mage::getModel('catalog/category')
    ->loadByAttribute('url_key', 'cat_urlkey');

How I can modify code so that, sub category load by url_key and respective parent category_id?

1 Answer 1


You can load the attributes collection and get it's first element:

$categories = Mage::getResourceModel('catalog/category_collection');

$categories->addAttributeToFilter('url_key', 'cat_urlkey');
$categories->addAttributeToFilter('path', array('like' => '1/15/%');

The second condition tells to take subcategories of the category with id 15.


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.