php - Magento 2 How to get category by url_key -


i try category in magento 2.0 url_key.

now i've got :

        $objectmanager = \magento\framework\app\objectmanager::getinstance();         $categoryfactory = $objectmanager->create('magento\catalog\model\categoryfactory');         $category = $categoryfactory->create()             ->addattributetofilter('url_key','my_category_url_key'); 

it returns me error :

error filtering template: invalid method magento\catalog\model\category\interceptor::addattributetofilter(array ( [0] => url_key [1] => my_category_url_key ) )

thanks.

/**  * @var \magento\catalog\model\categoryfactory  ****** inject in constructor ******  */ protected $categoryfactory;  --------- --------- --------- $categorys = $this->categoryfactory->create()             ->getcollection()             ->addattributetofilter('url_key','devops')             ->addattributetoselect(['entity_id']); echo "<pre>"; print_r($categorys->getfirstitem()->getentityid()); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -