How to get all subcategories ids of specific category id in magento2

1 Answer 1


You can use this to get all child category id of any particular category.

    $categoryId = 1; //Category ID
    $storeId = 1; //Store ID
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $categoryRepository = $objectManager->create("Magento\Catalog\Model\CategoryRepository");
    $category = $categoryRepository->get($categoryId,$storeId);
    echo "<pre>";print_r($category->getChildrenCategories()->getAllIds());echo "</pre>";

Hope this may help you.

  • Is above solution helpful to you ? Oct 20, 2019 at 13:02

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.