Php 我如何获得/展示WooCommerce最畅销的产品
我正在开发一个WooCommerce电子书商店,我想在我的主页上显示最畅销的产品列表Php 我如何获得/展示WooCommerce最畅销的产品,php,wordpress,woocommerce,product,Php,Wordpress,Woocommerce,Product,我正在开发一个WooCommerce电子书商店,我想在我的主页上显示最畅销的产品列表 我该怎么做?我可以用自定义WP_查询吗?还有其他方法吗?要获得畅销产品,您可以使用不同的方法: WordPress WP\u查询(此处仅限于20种畅销产品): $query_args = array( 'posts_per_page' => 20, // -1 (for all) 'post_type' => array( 'product' ), 'post_st
我该怎么做?我可以用自定义WP_查询吗?还有其他方法吗?要获得畅销产品,您可以使用不同的方法: WordPress WP\u查询(此处仅限于20种畅销产品):
$query_args = array(
'posts_per_page' => 20, // -1 (for all)
'post_type' => array( 'product' ),
'post_status' => 'publish',
'meta_key' => 'total_sales',
'order' => 'DESC',
'orderby' => 'meta_value_num',
);
$query = new WP_Query( $query_args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
// Your product data
the_title(); // Output product title
endwhile;
wp_reset_postdata();
else :
// No post found
endif;
[products best_selling limit="20"]
WooCommerce Shordcode(20款畅销产品):
$query_args = array(
'posts_per_page' => 20, // -1 (for all)
'post_type' => array( 'product' ),
'post_status' => 'publish',
'meta_key' => 'total_sales',
'order' => 'DESC',
'orderby' => 'meta_value_num',
);
$query = new WP_Query( $query_args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
// Your product data
the_title(); // Output product title
endwhile;
wp_reset_postdata();
else :
// No post found
endif;
[products best_selling limit="20"]
文件: