I have this function in my block.
public function getSubcategoryByUrlkey($url_key)
{ 
 $categoryCollection = $this->_categoryCollectionFactory->create() 
 ->addAttributeToFilter('url_key',$url_key)->getFirstItem(); 
 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() 
 ->addAttributeToFilter('url_key',$url_key); 
echo $categoryCollection->getSelect(); exit;