'Get the id of a WooCommerce product category by its name or slug

I have a wp template that I would like to assign to some pages. The template would ie. display all WooCommerce products that have the same master category name as the pages name itself.

By far I have tried using this code, but with no good output:

$idObj = get_category_by_slug($pagename);
$id = $idObj->term_id;
echo ": ". $id;

Unfortunately, the echo does not display anything.
Echoing $pagename works, and returns me the slug of the page.

Any good way I could make this work?



Solution 1:[1]

The code seems to be correct, try a var_dump to see what you are getting from get_category_by_slug($pagename)

$idObj = get_category_by_slug($pagename);
var_dump($idObj);

Solution 2:[2]

This is because the initial version of the secure version of NiFi is running in single user authentication mode. To add users, one would need to change this, and be able to edit the users and policies that can login and interact with NiFi, you will need to integrate NiFi with another login provider, such as LDAP or Kerberos. Once integrated to allow logins from LDAP or Kerberos, NiFi can be logged into from the initial admin account and be configured as desired.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Igor S Om
Solution 2 Mike R