【问题标题】:Hide specific woocommerce child category隐藏特定的 woocommerce 子类别
【发布时间】:2020-01-24 11:42:45
【问题描述】:

我正在使用此片段在 Woocommerce 父类别页面上隐藏子类别。

function exclude_product_cat_children($wp_query) {
if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
    $wp_query->set('tax_query', array( 
                                    array (
                                        'taxonomy' => 'product_cat',
                                        'field' => 'slug',
                                        'terms' => $wp_query->query_vars['product_cat'],
                                        'include_children' => false
                                    ) 
                                 )
    );
  }
}  
add_filter('pre_get_posts', 'exclude_product_cat_children')

有没有办法只隐藏父类别页面中的特定子类别?

提前致谢!

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    尝试将此功能用于您的功能。它可能会起作用......

    function exclude_product_cat_children($wp_query) {
    if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
        $wp_query->set('tax_query', array( 
                                        array (
                                            'taxonomy' => 'product_cat',
                                            'field' => 'slug',
                                            'terms' => array('cat', 'dog'), //product category slug to exclude
                                            'operator' => 'NOT IN',
                                        ) 
                                     )
        );
      }
    }  
    add_filter('pre_get_posts', 'exclude_product_cat_children');
    

    【讨论】:

      猜你喜欢
      • 2019-10-09
      • 2019-07-06
      • 1970-01-01
      • 2022-08-24
      • 2015-12-01
      • 1970-01-01
      • 2022-12-04
      • 2019-10-17
      • 1970-01-01
      相关资源
      最近更新 更多