How to Get Attribute Id by attribute code Magento 2?

Fetch Attribute Id from the attribute code in Magento 2 to using AttributeRepository Interface Class.

You need Entity type value and the attribute code.

Just instantiate the Magento\Eav\Api\AttributeRepositoryInterface class to retrieve the id value.

Here, We are fetching Product SKU attribute Id programmatically. You can pass any attribute value you want to retrieve it with entity type.

$getId = $this->getAttributeId();
The id will be the integer value of the attribute.

You can be interested to read Get Attribute id by product id Magento 2

Leave a Reply