2016-08-15 41 views
0

在我的WooCommerce商店中,我「啓用了」從商品目錄中隱藏缺貨商品「。此選項會導致個別頁面上的產品變體變得不可見隱藏缺貨 - 「pre_get_post」商店頁面上的能見度分析

我只想在歸檔頁面(搜索,類別)上申請「隱藏缺貨中的項目」選項

這裏是我的代碼:

function featured_posts($query) { 
    if (! $query->is_main_query()) return; 

    //What goes in here? 
} 
add_action('pre_get_posts', 'featured_posts'); 

我怎樣才能做到這一點?

感謝

回答

0

試試這個

你必須爲檢查頁面做如下

function featured_posts($query) { 

    if(is_product_category() || is_search()){ 
     if (! $query->is_main_query()){ 
      return; 
     } 
    } 
    .... 
} 
add_action('pre_get_posts', 'featured_posts'); 
+0

您好,我太累了,解釋什麼實際發生。我明天會回到這個位置,清楚地解釋我的問題。 – Jason