php - Get the id of a WooCommerce category, by name -


i have wp template assign pages. template ie. display woocommerce products have same master category name pages name itself.

by far have tried using code, no output:

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

unfortunately, echo not display anything.
echoing $pagename works, , returns me slug of page.

any way make work?

with custom taxonomy recommended use get_term_by() instead :

$category = get_term_by( 'slug', $pagename, 'product_cat' ); $cat_id = $category->term_id 

reference: get category id category slug…


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -