1

I have a list of category names, and I was wondering if there a way in Magento to lookup the category id using the name? Please advise the easiest way to do this.

1

Regina Nickles,you can do this by loadByAttribute();

For single category:

$category=Mage::getModel('catalog/product')->loadByAttribute('name',$name);
$id=$category->getId();

For getting multiple categories

$collection = Mage::getModel('catalog/category')->getCollection()
            ->setStoreId($storeId)
            ->addAttributeToSelect('name')
            //->addAttributeToSelect('*')
        ->addAttributeToFilter('name',array('like'=>$name));

 $allIds = $collection->getAllIds();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.