Magento 2 is well known for it’s capacity to extending the features. Today’s article we will be discussing how to get product collection based on custom attribute (drop down attribute value).
For dropdown attribute, We can filter using dropdown option ID instead of Label.
So your code is like below.
$productcollection = $this->_productCollection
->addAttributeToSelect('*')
->addAttributeToFilter('brand', 20)
->load();
The above 20 is the value from the drop down in the admin area. In my case, that was a brand called Sony.
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply