Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I installed the woocommerce plugin.

my page url is like this

products-and-service - is the main category servicecat1 - is the sub category

In this page the list of products are displayed.

I want to get the category id of the subcategory (i.e servicecat1)

I used the following code

  $q_cat = get_query_var('cat');


     $term_list = wp_get_post_terms('servicecat1','product_cat');

But it is not working.

How to get this id. I used this code in content-product.php

Please help to get this.

share|improve this question

1 Answer 1

Use this

$product_terms = wp_get_object_terms( 17, 'product_cat', array( 'fields' => 'all' ) );

and then get the parent cat id and move all sub cat into an array.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.