First you need to loop trough the posts, get all the 10 posts, based on their sales number.
Then, you need to check if the current product ID is equal to any ID of the products you looped.
If it is, then you show ‘best seller’ tag for the product.
In your code, you are probably mixing stuff.
Your code should be something like this:
$post_type_query = new WP_Query(
array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => '10',
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
)
);
$products_ID = array();
while ($post_type_query->have_posts()){
$post_type_query->the_post();
$products_ID[] = get_the_ID();
}
wp_reset_query();
return $products_ID;
$id = get_the_ID();
if (in_array($id, $products_ID)) {
echo "Best Seller";
}
Related Posts:
- Query WooCommerce orders where meta data does not exist
- WP_Query for WooCommerce Products
- how to retrieve specific product attribute value in an sql query?
- merge two query arguments into one WP_Query call
- Get all products which have both product category
- Woocommerce Get Orders By Meta Value
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- When should you use WP_Query vs query_posts() vs get_posts()?
- order by numeric value for meta value
- Wp get all the sub pages of the parent using wp query
- Return only Count from a wp_query request?
- How to query for most viewed posts and show top 5
- WP_Query vs get_posts
- WP_Comment_Query pagination, delving into the unknown
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- WP_Query: Exclude hidden products from WooCommerce product list
- Make a WP Query search match exactly the search term
- How to query only for products with status “in stock” in WooCommerce? [closed]
- WP_Query: query posts by ids from array?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Sort posts by category name and title
- How to uniquely identify queries?
- What is the most efficient way of querying posts based on visits and date for current day?
- Custom WP_Query order by post_meta and (author) user_meta
- pre_get_posts with get_posts
- author.php with ACF and CPTs
- Query Custom Meta Value with Increment
- Changing a theme’s search function to only show results from woocommerce?
- Get WooCommerce best selling products for the current month [closed]
- When should you use wp_reset_postdata vs wp_reset_query?
- Get posts by meta data OR title
- Identify which loop you are hooking into; primary or secondary?
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- How to make an activities stream mixing posts and comments?
- Duplicate Queries
- Woocommerce query by price range and custom meta key
- How to query for a week using key => value WP_Query argument notation?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- Order posts by tags count?
- SQL query equivalent to WP User Query
- Add and in the header while looping over custom query in page template
- How to get the posts published in last two days using WP_Query?
- Highlighting Sub topic in a post?
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Which custom query am I in and how can I access its properties & methods?
- How to count post type that has a particular term?
- Retrieve products with specific attribute and in category – woocommerce
- How to combine tax_query and date_query in WordPress
- Finding the next 5 posts
- Dynamically Override Fancy Title – Part II
- Transient pagination not working properly
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Can not switch the queried post in pre_get_posts hook
- Find all product that contain terms with %keywords% in WP_Query
- Display featured products through custom loop in WooCommerce 3 [closed]
- view queries made?
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- WP Query – Get WooCommerce Products with variation that is in stock
- WordPress custom archive page
- How to speed up wp_query, took more 5s to run against 100k posts
- WP_query category__in not working, only pulls from first category
- How to detect custom query inside `posts_where` hook?
- Pass the same object to multiple widgets in a template with one query
- Is temporarily overwriting $wp_query a bad idea?
- Get the post permalink within the loop but without additional DB query
- Query Set Order By Author
- List the 5 most recent child pages
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Retrieve or Query Pages by ID
- Search product by brand name in wp_query
- Get product list of given category
- How do you query wordpress posts using a math formula between multiple meta field values?
- How to exclude products by tag from woocommerce shop page?
- Custom Post order for homepage
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Get image of latest post from taxonomies/categories
- How to output different posts per page?
- Display related products with custom output
- How to do a query on custom taxonomies that is uncategorised?
- Page navigation doesn’t show when query category
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- WooCommerce Only OnSale Products Loop Snippet [closed]
- Undefined WP_Query::has_posts()?
- Is it possible to dynamically get queried term AND taxonomy?
- Empty tax_query array returns an empty array
- Meta Query for specific months
- What is considered a default query for the request filter?
- How do I search inside specific taxonomies in WordPress
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- $wpdb insert is not work
- Pass array of taxonomy terms to wp_query
- Different string for specifed post type on posts listing at homepage
- How to orderby meta_value_num with dollar ($) sign
- if/else on custom query gives 200 OK when condition not met?
- Pull post meta with post_query?
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?