WooCommerce – exclude category from shop
-
Preface: This is my first time with WP and Woo and my site isn’t live yet. I’ve spent hours/days trying to figure this out. ??
Mine is a photography site. Galleries has all product categories listed in the sub-menu and shows the appropriate thumbs. I created a page called Projects to which I want to show them separately from the Galleries page. But when I added the category for my current project it shows up in Galleries, even though it’s not in the sub-menu.
I found this snippet that I’m supposed to use:
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() && is_shop() ) { ? $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'knives' ), // Don't display products in the knives category on the shop page 'operator' => 'NOT IN' ))); } ? remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); ? }
But it doesn’t work and gives me the dreaded white screen. I cannot figure out what I’m doing wrong. I changed in_shop to in_galleries as I changed it’s name. I put in the slug with hyphens. I tried putting in the multi-word name in terms with spaces, hyphens and underscores, no joy either way.
I looked in Firebug to see if I could find a post #, product #, category #, or whatever for that specific one, but no joy either.
I would greatly appreciate any help with this as it’s the only thing (outside of adding more prints) that is keeping me from going live. Thanks in advance for any assistance!
WooTheme – Mystile and WooCommerce are up to date
- The topic ‘WooCommerce – exclude category from shop’ is closed to new replies.