I need to get best selling product from woocommerce here i have a query that bring me best selling product but there is no data about product images or product URl i need those too.
SELECT * FROM wp_posts
INNER JOIN wp_postmeta
ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1
AND ( wp_postmeta.meta_key = 'total_sales' )
AND wp_posts.post_type = 'product'
AND (wp_posts.post_status = 'publish')
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value+0
DESC, wp_posts.post_date ASC LIMIT 0, 16
i tried to use “SELECT TO” but mysql does not support this also its not suppirt “IN” !
2
Answers
here my solution :
that's all I hope it's useful for someone.
You can use this code for retrieving the best selling product in the loop.