我正在创建一家商店。我有很多类别,例如:
cat1 (1) - cat1.1 (3) - cat1.1.1 (2)
如果我去cat1,我只想显示这个类别中的1种产品,而不是cat1.1和cat1.1.1中的产品,我想显示cat.1.1。
对于cat 1.1,我想展示3种产品和cat1.1.1
我怎么能这么做?它应该是动态的
发布于 2020-02-07 09:33:23
放入functions.php文件
function excludeChildCategory($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',
                    'terms' => $wp_query->query_vars['product_cat'],
                    'field' => 'slug',
                    'include_children' => false
                )
            )
        );
      }
}
add_filter('pre_get_posts', 'excludeChildCategory');https://stackoverflow.com/questions/60109379
复制相似问题