我一直試圖從SHOP頁面隱藏特定類別。我發現這個代碼:在WooCommerce商店頁面中隱藏類別
add_filter('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;
$q->set('tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('CATEGORY TO HIDE'),
'operator' => 'NOT IN'
)));
remove_filter('pre_get_posts', 'custom_pre_get_posts_query');
}
我已經將這些代碼在我的主題function.php文件,但我沒有實現的結果......
任何人可以幫助我嗎?
請修正您帖子的標題。所有大寫字母只是簡單的粗魯.... – talonmies