How to filter product collection using more than two category. In magento1, we can use ->addAttributeToFilter('category_ids',array('finset'=>'36,37')); but how can i do this in magento2? Also i have checked Multiple category filter extension. Collection show correct but other filters (Like Price,color) and collection size and pagination give a wrong data.

1 Answer 1


Add this categories filter

$catalog_ids = array('10','20');

$collection->addCategoriesFilter(array('in' => $catalog_ids));

Or use below full product collection with categories filter

public function __construct( \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory ) { $this->collectionFactory = $collectionFactory; }

$catalog_ids = array('10','20');

$collection => $this->collectionFactory->create();


$collection->addCategoriesFilter(array('in' => $catalog_ids));

I hope this might help you.


  • Same code i used but pagination and total product and price filter show wrong data.
    – nil108
    Commented Nov 16, 2017 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.