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 know many people asked for this question but I didn't find a proper way to do it. How to add a simple meta_query (product_cat) before the execution of the shop page's query.

Maybe by using a filter ?



share|improve this question
up vote 5 down vote accepted

The shop page is actually an archive page for posts of type 'product'. Its template is in woocommerce/archive-product.php.

You need to use the pre_get_posts action to preprocess the query before the loop, conditional_tags to recognize that you are in the product archive page, and a taxonomy query to filter the product categories, which belong to the taxonomy 'product_cat'.

For example, the following (placed in your theme's functions.php or in a plugin) will display only products with product category 'type-1':


 function shop_filter_cat($query) {
    if (!is_admin() && is_post_type_archive( 'product' ) && $query->is_main_query()) {
       $query->set('tax_query', array(
                    array ('taxonomy' => 'product_cat',
                                       'field' => 'slug',
                                        'terms' => 'type-1'

You can also exclude categories by using 'operator' => NOT IN, and 'terms' can be an array of product category slugs.

A good introduction to query customization is http://www.billerickson.net/customize-the-wordpress-query/

share|improve this answer
Thank you for your clear explanations... I know my question is not new, but I didn't find a good answer elsewhere. I try to use the good practices so I prefer ask to the community :) – aguidis Apr 29 '13 at 10:13

This worked for me:

[product_category category="YOUR CATEGORY" per_page="8" columns="3" orderby="date" order="desc"]
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.