【问题标题】:display two woocommerce categories on front page在首页显示两个 woocommerce 类别
【发布时间】:2021-12-02 18:04:34
【问题描述】:

我有两个类别,称为移动设备和笔记本电脑,我想在主页上同时显示这两个类别。我使用了这段代码,但它只显示了其中一个类别。谢谢你的帮助

  <?php $products= new WP_Query(
 array(
     'post_type'=>'product',
     'posts_per_page'=>'-1',
     'product_cat' => 'mobile+laptop',
     'orderby' => 'rand',
    
 )
 ); ?>

【问题讨论】:

    标签: php html wordpress woocommerce e-commerce


    【解决方案1】:

    您可以使用tax_query。试试下面的代码。

    <?php 
    $products = new WP_Query(
        array(
            'post_type'      => 'product',
            'posts_per_page' => -1,
            'orderby'        => 'rand',
            'tax_query'      => array(
                'relation' => 'AND',
                array(
                    'taxonomy' => 'product_cat',
                    'field' => 'slug',
                    'terms' => 'mobile'
                ),
                array(
                    'taxonomy' => 'product_cat',
                    'field' => 'slug',
                    'terms' => 'laptop'
                )
            ),
        ) 
    ); 
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      相关资源
      最近更新 更多