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
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {

$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'membership' ), // Don't display products in the membership category on the shop page
'operator' => 'NOT IN'

remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );


I used the above code to exclude the membership category in the shop page. Its working on the shoppage but it display in the homepage i need to know how to exclude the particular category in all those page . Basic idea is to be download the products only for the membership. I added the membership as the seperate product category , Also i exclude that category from the shop page but it displaying in the homepage . I don't how to do this in the woocommerce plugin.

share|improve this question
I've developed a plugin that will help you doing it: http://www.wpworking.com/product/woocommerce-exclude-categories-pro/ Best Regards – Alvaro Neto Mar 7 '14 at 17:53

Include it in your woocommerce-core-functions.php to hide that category on "Shop" Page in your woocommerce site.

share|improve this answer
Please some example code; it is hard to see what you mean. Thanks. – toscho Mar 30 '13 at 18:54

I have simply commented these two lines and found to be working. I am not sure about its subsequent consequences on commenting these lines.

//if ( ! $q->is_main_query() ) return;
//if ( ! $q->is_post_type_archive() ) return;
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.