How to query Popular Products and Featured products in same loop
-
I’m trying to query for best selling products (popular) and featured products using one loop. And, potentially being able to add an identifier to each product –as a class– to be able to filter them.
I’ve been able to query for the featured products like so:
$args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => '_featured', 'meta_value' => 'yes' ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); // stuff endwhile; else : // Nothing endif; wp_reset_postdata();
And for the Popular Products, this:
$args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num' ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); // stuff endwhile; else : // Nothing endif; wp_reset_postdata();
I’ve already tried some stuff to join them together with no luck.
Any help and/or ideas to be able to add an identifier class are greatly appreciated.
- The topic ‘How to query Popular Products and Featured products in same loop’ is closed to new replies.