【问题标题】:woocommerce get product order by viewwoocommerce 按视图获取产品订单
【发布时间】:2022-01-21 13:28:07
【问题描述】:

我通过以下方式获得product

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 15,
    'tax_query' => array(
            array(
                'taxonomy' => 'product_cat',
                'field' => 'id',
                'terms' => $theCat
            )
        )
    );
$post= new WP_Query( $args );

我想通过view 订购产品,所以我做了:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 15,
    'tax_query' => array(
            array(
                'taxonomy' => 'product_cat',
                'field' => 'id',
                'terms' => $theCat
            )
        ),
    'order' => 'ASC', // add this
    'suppress_filters' => false, // add this
    'orderby' => 'post_views' // add this
    );
$post = new WP_Query( $args );

但仍然显示相同的结果,有什么想法吗?

【问题讨论】:

  • 'post_views' 是帖子元字段吗?
  • @Mokhless 其实不确定,我认为是

标签: php wordpress


【解决方案1】:

不确定这是否有帮助,但不要尝试“ASC”,而是尝试“DESC”?

【讨论】:

    猜你喜欢
    • 2021-12-06
    • 2021-04-23
    • 2016-12-26
    • 2021-11-06
    • 2022-07-08
    • 2021-01-25
    • 2016-09-13
    • 2019-01-21
    • 1970-01-01
    相关资源
    最近更新 更多