【发布时间】:2015-03-17 10:29:14
【问题描述】:
我想展示过去 30 天内 WooCommerce 中最畅销的产品。只是为了展示总体上最畅销的商品,提供的代码没有问题。
代码缺少的是您在特定时间段内获得销售的部分。 meta_query 应该是做到这一点的关键,但我不确定如何。任何帮助表示赞赏!
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 4,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
woocommerce_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
【问题讨论】:
标签: php woocommerce wordpress