Magento 2 get product collection filter by Attribute


Magento 2 get product collection filter by Attribute– We often need to load product collection filter by custom attribute. It is very simple to add attribute filter in product collection. Here in this article, we are going to explain how you can add attribute filter to product collection.


Magento 2 get product collection filter by Attribute Example

You can add attribute filter to collection simply as below-

Magento 2 get product collection filter by Attribute

Example:

$productcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection')
        ->addAttributeToSelect('*')
        ->addAttributeToFilter(
            array(
                array('attribute'=>'color','eq'=>'red')
            )
        );

The above example will give you output with filter attribute color. On the same way you can add other attributes filter.


Advertisements

Add Comment

📖 Read More