Skip to content

Instantly share code, notes, and snippets.

@carlosleopoldo
Last active September 12, 2019 23:09
Show Gist options
  • Save carlosleopoldo/5897789 to your computer and use it in GitHub Desktop.
Save carlosleopoldo/5897789 to your computer and use it in GitHub Desktop.
Select users in WordPress without specific user meta key and user id upper than...
-- Select users in WordPress without specific user meta key
-- * Replace meta_name for your meta key
-- * Replace > 0 for the minimum user ID
SELECT wp_users.ID
FROM wp_users
WHERE wp_users.ID > 0
AND wp_users.ID NOT IN (
SELECT DISTINCT user_id FROM wp_usermeta WHERE meta_key = 'meta_name'
)
ORDER BY wp_users.ID ASC
@nabtron
Copy link

nabtron commented Apr 11, 2016

Why are we checking: wp_users.ID > 0 ?

@carlosleopoldo
Copy link
Author

@nabtron you can change the ID by which you need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment