I need to get attribute_id from eav_attribute table, I have attribute_code and frontend_label, my sql query will be some thing like this.

select attribute_id from eav_attribute where attribute_code = 'sb_store_id'

What will be its equivalent magento statement.


2 Answers 2


you can get id from attribute code like that

$attribute_code = "sb_store_id"; 
$attribute_details =
Mage::getSingleton("eav/config")->getAttribute('catalog_product',    $attribute_code);

echo $attribute_details->getAttributeId(); //marius suggestion
  • 2
    you can just call $attribute_details->getAttributeId() instead of calling getData first.
    – Marius
    Feb 11, 2016 at 9:09

Here is how you should do it.

You need to know the entity type to be able to get it (product,category...).

Example for product:

$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY , 'sb_store_id');

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