Geçenlerde bir projede lazım olmuştu bazı kategorideki ürünleri mağaza sayfasında göstermek istemiyorduk. Bunu funtions.php dosyasına ekleyeceğiniz kod ile kolayca uygulayabilirsiniz. “kategori1” ve “kategori2” yazan yerleri kendinize göre düzenleyiniz.
add_action( 'pre_get_posts', 'remove_cat_from_shop_loop' );
function remove_cat_from_shop_loop( $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( 'kategori1', 'kategori2'), // Change it to the slug you want to hide
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'remove_cat_from_shop_loop' );
}