Im trying to remove a particular category “knives” from the shop page using this piece of code from the woo commerce documents whilst it does remove the product it renders the filter widgets on the left hand side inoperable clicking on any filter just returns all items to shop.
I also want the products within knives to remain hidden even if a filter is selected in the shop page which relates to them. However I want them to show when using XTEMOS Product category.
ultimately what i am try to achieve is to have a category to appear only on its on page and not within the general shop.
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’ );
}