Magento2 – How to Get Attributes Based on Attribute Set ID or Name

attribute-setattributesmagento2product-attribute

In Magento2, How can get the all (product) Attributes based on the Attribute Set Id or Attribute Set Name in the Custom Product List Page.

Best Answer

you can make use of the Magento\Catalog\Api\ProductAttributeManagementInterface

$attributeSetId = 20;//your_attributeSetId
$productAttributesManagement = $this->objectManager->create('Magento\Catalog\Api\ProductAttributeManagementInterface');
$productAttributes = $productAttributesManagement->getAttributes($attributeSetId);

Please note that you should not be using the object manager directly. This is just for demonstration