I have number of sub categories under main category. I have to get only four sub categories of main category. Any solution for this?
Here is the code for get sub categories:
$catId = 3; // Parent Category ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$subcats = $subcategory->getChildrenCategories();
foreach ($subcats as $subcat) {
echo $subcat->getName();
}
}