Last active
August 29, 2015 14:20
-
-
Save TimBHowe/7a2fd7763f4adfc0430b to your computer and use it in GitHub Desktop.
How to Delete Users With SQL Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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%); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SELECT
user_id
FROMwp_usermeta
WHEREmeta_key
= 'wp_capabilities' ANDmeta_value
LIKE '%customer%'