Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Build a list of user IDs, ordered by the number of known (WooCommerce) subscriptions each user is associated with.
SELECT meta_value AS user_id,
COUNT(*) AS subscription_count
FROM wp_posts
JOIN wp_postmeta ON ID = post_id
WHERE post_type = 'shop_subscription'
AND meta_key = '_customer_user'
GROUP BY meta_value
ORDER BY subscription_count DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.