Magento – Load A Product By Any Attribute


While generally we load a product in Magento by its id, it is also possible to load it by any of its attribute. To do that use the following code –

$_p = Mage::getModel('catalog/product')->loadByAttribute('attr_name', $attrib);

Just replace ‘attr_name’ with the name of the attribute and $attrib with the value and then Magento will fetch matching products.

This entry was posted in Magento, PHP and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *