Last active
November 20, 2022 06:24
-
-
Save aslamdoctor/719e4cc5b6c33f7628f2ab30ed3d441d to your computer and use it in GitHub Desktop.
Woocommerce : Get popular products using wp_query
This file contains hidden or 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(); | |
?> |
Thanks, Man...!
Use get_the_title(); instread of the_title();.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Man!