Magento – Get Attribute model by attribute_code in Magento

magento

How could I get Attribute model (from: eav_attribute table) by attribute_code in Magento?
Notice:
– I don't care what is entity_type.
Thank you so much.

Best Answer

You have to know entity_type because you can have the same attribute_code for different entities. So to get attribute model:

$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode($entity_type, $attributeCode);

$entity_type parameter can be numeric (id directly), string (for example 'catalog_product' or Mage_Catalog_Model_Product::ENTITY) or it can be instance of model Mage_Eav_Model_Entity_Type

Related Topic