How to get category by url key in Magento 2

  Here is the sample code to get category by category url key. categoryFactory = $categoryFactory; } public function getCategory($urlKey, $parentCatId) { $categories = $this–>categoryFactory->create()–>getCollection() –>addAttributeToFilter(‘url_key’, $urlKey) –>addAttributeToSelect([‘entity_id’]); return $categories; } } Now you can get category by using function getCategory($urlKey) $urlKey = ‘cloths’; $category = $this–>getCategory($urlKey); print_r($category->getData()); Multiple categories may…
Read More