Forked from aslamdoctor/woocommerce-popular-products.php
Created
March 24, 2022 08:23
-
-
Save qant/1dc8a7c10ffa92e727bb4be14a31c1e0 to your computer and use it in GitHub Desktop.
Woocommerce : Get popular products using wp_query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => array( 'product' ), | |
'meta_key' => 'total_sales', | |
'orderby' => 'meta_value_num', | |
'order' => 'desc', | |
'posts_per_page' => 5 | |
); | |
$popular_products = new WP_Query( $args ); | |
if ( $popular_products->have_posts() ) : | |
while ( $popular_products->have_posts() ) : $popular_products->the_post(); | |
the_title(); | |
echo '<br/>'; | |
endwhile; | |
endif; | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment