I am implementing multiple category filters for layered navigation. I am getting the result as per my requirement but the collection size is coming wrong remains same as the parent categories collection size.

Is there any other way to implement this functionality.

I have modified the following code :

public function apply(\Magento\Framework\App\RequestInterface $request)
        $categoryId = $request->getParam($this->_requestVar) ?: $request->getParam('id');
        if (empty($categoryId)) {
            return $this;


        $category = $this->dataProvider->getCategory();


        if ($request->getParam('id') != $category->getId() && $this->dataProvider->isValid()) {
            $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $categoryId));
        return $this;

replaced the addCategoryFilter($category) with addCategoriesFilter('eq' => $categoriesArray);

But as the layered navigation count is coming from somewhere else and not from product collection.

would like to know from where. And how could I apply multiple category filters there?

  • 1
    Could you please share the code ? on which file did you filter the collection ? Apr 13, 2017 at 11:24
  • 1
    added the code please take a look Apr 13, 2017 at 11:33
  • 1
    Could you also give me the file name or path ? Apr 13, 2017 at 11:36
  • 1
    File name : Category.php Path : root_dir/vendor/magento/module-catalog-search/Model/Layer/Filter/Category.php Apr 17, 2017 at 7:36

2 Answers 2


Please take a look at the research I've done concerning this and the final solution (my answer to the question) here: Magento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methods


To Implement multiple category filter in magento 2enter image description here

  • What a pointless answer
    – omsta
    Feb 11, 2021 at 13:18

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.