Magento – Magento 2: How to filter category by store id

catalogmagento2store-id

I want to filter category by store id. Used the following code, but it is not working.

$collection = $this->categoryCollectionFactory->create();
        $collection->addAttributeToSelect('*')
        ->setStoreId(0);

Best Answer

Try below code. this is working for me.

$collection = $this->categoryCollectionFactory->create();
$collection->addAttributeToSelect('*');        
$collection->addStoreFilter($this->_storeManager->getStore($store_id));