Skip to content

Instantly share code, notes, and snippets.

@TimBHowe
Last active August 29, 2015 14:20
Show Gist options
  • Save TimBHowe/7a2fd7763f4adfc0430b to your computer and use it in GitHub Desktop.
Save TimBHowe/7a2fd7763f4adfc0430b to your computer and use it in GitHub Desktop.
How to Delete Users With SQL Queries
--If you want to remove WordPress user(s) and all their data here are SQL queries you should run over your database (just replace %USERS IDs% with ids of users need to be deleted. - http://www.loneshooter.com/wordpress-how-to-delete-users-with-sql-queries/ --
-- Deletes any comments from specific user(s)
DELETE FROM wp_comments WHERE user_id IN (%USERS IDs%);
-- Deletes post meta for specific user(s)
DELETE t1 FROM wp_postmeta t1
LEFT JOIN wp_posts t2 ON t1. post_id = t2.ID
WHERE post_author IN (%USERS IDs%);
-- Deletes posts for specific user(s)
DELETE FROM wp_posts WHERE post_author IN (%USERS IDs%);
-- Deletes the users account meta
DELETE FROM wp_usermeta WHERE user_id IN (%USERS IDs%);
-- Deletes the users account
DELETE FROM wp_users WHERE ID IN (%USERS IDs%);
@TimBHowe
Copy link
Author

SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%customer%'

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