从商店页面中的特定类别中排除产品
/** * Remove products from shop page by category * */ function woo_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( 'shoes' ), https:// Don't display products in the shoes category on the shop page 'operator' => 'NOT IN' ))); } remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); } add_action( 'pre_get_posts', 'woo_custom_pre_get_posts_query' );
在哪里添加此代码?
将PHP代码放在主题或子主题functions.php文件的底部。