Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我如何获得/展示WooCommerce最畅销的产品_Php_Wordpress_Woocommerce_Product - Fatal编程技术网

Php 我如何获得/展示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

我正在开发一个WooCommerce电子书商店,我想在我的主页上显示最畅销的产品列表


我该怎么做?我可以用自定义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"]
文件:


为畅销书创建一个类别,并在您的产品帖子类型和类别上进行自定义循环