Abhishek Porwal
Abhishek Porwal

Reputation: 1

How can I use addAttributeToFilter to search in Magento for a multi-select value in db?

I have values in database in array and I want to search values also from an array.

For example :

I have an array ('13,14') and in database I have values like (13,14) or (13) or (14) or (15). So when I search ('13,14') results should appear with values containing at least one of them.

Upvotes: 0

Views: 67

Answers (1)

OddBrew
OddBrew

Reputation: 498

I'm assuming you're using a collection, as addAttributeToFilter() is a collection method. Here's how your filter your collection with a set of possibilities, for a given attribute :

$myCollection->addAttributeToFilter('id', array('in' => array('13','14')));

'id' being the name of your attribute. You can also use the operator nin instead of in, to specify a set of values you don't want your attribute value to be in. Check the other operators here : https://fishpig.co.uk/magento/tutorials/addattributetofilter/

Upvotes: 0

Related Questions