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

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

Try below code. this is working for me.

$collection = $this->categoryCollectionFactory->create();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $categoryCollection = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');

    $categories = $categoryCollection->create();
    $categories->setStore('0'); /* set here your store id */

    foreach ($categories as $category) {
        echo $category->getName() . '<br />';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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