L
L
ligisayan2016-03-01 10:41:11
WordPress
ligisayan, 2016-03-01 10:41:11

How to get product category id by its label?

Hello! There is a site on wordpress + woocommerce and there is a category label for which I want to get its id, but the function https://codex.wordpress.org/Function_Reference/get... does not work
$idObj = get_category_by_slug('category-slug');
returns bool (false) why and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
ligisayan, 2016-03-01
@ligisayan

thought it might be useful for someone

$itemcat = get_query_var('term');
$category = get_term_by('slug', $itemcat, 'product_cat', 'ARRAY_A'); 
$category_id = $category["term_id"];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question