I have created a custom attribute for product in Magento 2.

But how to get that value by sku or id in Magento 2 ?

I have got the product id by

$product = $this->productRepository->get($productsku);
$id = $product->getEntityId();

how to get custom attribute value if my attribute name is 'my_custom_attribute' enter image description here


1 Answer 1


This is how i get a custom attribute from a product

use \Magento\Catalog\Api\Data\ProductInterfaceFactory

$product = $this->productFactory->create()->load($id);
$value_code =  $product->getAttributeText($attr);

Hope this can help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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