Magento – Magento2 addAttributeToFilter not working with Multi Select Attribute

attributesmagento2multiselect-attribute

I am try to filter Product collection attribute Multi Select with Following code but it not working with IN or FINESET.

\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory 

$collection1 = $this->collectionFactory->create();
$collection1->setStore(1);
$collection1->addAttributeToFilter('industry', array('in' => array(7)));

Suppose Product attribute "industry" contain 8,7,2 In this case above filter not working.

anyone have idea about this.

Best Answer

It working fine with following syntax.

$collection->addAttributeToFilter($attribute,
    array(
        array('finset'=> array('237')),
        array('finset'=> array('238')),
        array('finset'=> array('239')),
    )
);