I'm currently working on shop page and custom product loop. With WP_Query I can succesfully display products based on meta_key and meta_val but i run into trouble. Now i have to display all products from category and as argument i need to pass category_id. This is my code:

$args = array(
            'post_type' => 'product',
            'posts_per_page' =>12,
    //   get category by slug is working -
            'product_cat' =>  'products-from-cat-40',

I know that woocommerce have slightly different query arguments than wordpress so i've tried so far:

  • product_cat_id
  • product_cat
  • product_category
  • product_category_id
  • cat
  • cat_id
  • category_id

As ID i passed both integer and string but still nothing works. I've searched trough internet for list of viable Woocommerce WP_Query arguments and i couldn't find it. Can anyone help? I'll much appreciate.

  • And does the category with slug 'products-from-cat-40' really exist? Commented Apr 25, 2018 at 6:27
  • That was only example. The problem is solved so i guess you want to use this code in your case? Commented Apr 25, 2018 at 16:30

1 Answer 1


For custom taxonomies, including Product Categories, you should use the tax_query argument:

$args = array(
    'post_type'      => 'product',
    'posts_per_page' => 12,
    'tax_query'      => array(
            'taxonomy' => 'product_cat',
            'terms'    => 40,
  • 2
    You should also avoid using WP_Query() to retrieve WooCommerce products. See more info here: cfxdesign.com/…
    – cfx
    Commented May 24, 2018 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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