In Magento 2 all the subcategories aren't showing in layered navigation. I am having categories structure for 4th level. If any 3rd categories having sub categories along with products - then it isn't showing at layered navigation.

Is there any settings available for same? Highlighted categories aren't showing in left from screenshot.enter image description here


2 Answers 2


Yes there is. U can go to stores-->configuration -->catalog --> category top navigation --> maximal depth (0= no limits).

Also if u use a custom mega menu or something they have also a setting for this

  • Above changes are already set. Its not working. Apr 25, 2016 at 6:02
  • Which theme / mega menu extension do you use?
    – Versdivers
    Apr 25, 2016 at 12:12

You need to override magento2\vendor\magento\module-catalog\Model\Layer\Filter\Category.php and update _getItemsData() function with below code:

protected function _getItemsData()
    /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
    $productCollection = $this->getLayer()->getProductCollection();
    $optionsFacetedData = $productCollection->getFacetedData('category');
    $category = $this->dataProvider->getCategory();
    $categories = $category->getChildrenCategories();

    $collectionSize = $productCollection->getSize();

    if ($category->getIsActive()) {
        foreach ($categories as $category) { 
            $categoryManager = $this->categorys->load($category->getId())
                                ->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', 4);

            if ($category->getIsActive() && $categoryManager->count()>0)
    return $this->itemDataBuilder->build();

I Hope this will help you.

  • when Im entering "echo 'In getItemsData'; exit;" at start of function then trying to use layered navigation, then execution not stop means its not calling that function then how it will work? Also I have replace core function with your function but result seems unchanged. May 30, 2017 at 9:26

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.