I have this function in my block.

public function getSubcategoryByUrlkey($url_key)

    $categoryCollection = $this->_categoryCollectionFactory->create()      

    echo $categoryCollection->getSelect(); exit;

    return $childs = $categoryCollection->getChildrenCategories();


I cannot view anything from this collection. My Magento version is Magento ver. 2.2.2. What is the mistake I am doing here?

echo $categoryCollection->getSelect();

this also not retrieve the query

Update I am getting this error

Fatal error: Uncaught Error: Call to undefined method Magento\Catalog\Model\ResourceModel\Category\Collection::getChildrenCategories()

1 Answer 1


Remove ->getFirstItem() then it will show the query

$categoryCollection = $this->_categoryCollectionFactory->create()      

echo $categoryCollection->getSelect(); exit;

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.