Home » Magento, Magento 216 January 2017

Magento 2: Get Attribute Id, Name from Attribute Code

This article shows how you can get attribute name or label, id, entity_type, etc. by attribute code in Magento 2.

If you would like get attribute name and value in Magento 1 then you may refer to this article: Magento: How to get attribute name and value?

Let’s see how you can get attribute ID and attribute name from attribute code.

Here is the code that you need to write in your Block class.

Below are the code to be written in template file. The sample output of the codes are also given below.

Multiple entity types can have same attribute code. For example: entity type ‘catalog_product’ & ‘catalog_category’ both have ‘name’ attribute code. So, “getAttributesByCode” function can return object of size greater than 1.


Get Product Attribute data by attribute code.


Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.