Skip to content

Instantly share code, notes, and snippets.

@nicomollet
Created January 20, 2022 14:23
Show Gist options
  • Save nicomollet/473c4512123c084ae5f04058f0afd81e to your computer and use it in GitHub Desktop.
Save nicomollet/473c4512123c084ae5f04058f0afd81e to your computer and use it in GitHub Desktop.
WooCommerce most/least sold products Mysql query
# Exclude product variations since they don't include the "total_sales" meta key filled by WooCommerce
SELECT ID, post_title, post_status, post_modified, meta_value
FROM wp_posts
INNER JOIN wp_postmeta ON wp_postmeta.post_id=wp_posts.ID
AND wp_postmeta.meta_key='total_sales'
WHERE post_type='product'
ORDER BY CAST(`wp_postmeta`.`meta_value` as UNSIGNED) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment