我不想展示某个类别的产品。我设法做到了这一点,但出现了一个问题,如果产品属于另一个类别,它们也不会出现。 我不知道如何为此调整我的代码。 你有什么想法吗?
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'bookfair' ),
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );