WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed the woocommerce plugin.

my page url is like this http://sitename.com/product-category/products-and-service/servicecat1/

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

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.