Main menu

Delete all spam users in wordpress

Spamming is most common attack on new wordpress site and without security in can make a massive damage. Spammer can create thousands of comment or subsciber on your wordpress blog.

I also faced the same issue issue year ago, when spammers created thousands of users on my newly created blog. Here is a two step SQL query you can delete them.

  1. Check for the user who don’t have any comments or post and delete them.
  2. Delete their metadata.

Before deleting check for the users who don’t have any post or comments.

SELECT * FROM wp_users WHERE ID NOT IN
 (SELECT post_author FROM wp_posts UNION SELECT user_id FROM wp_comments)

Delete users who don’t have any post of comment

DELETE FROM wp_users WHERE ID NOT IN
 (SELECT post_author FROM wp_posts UNION SELECT user_id FROM wp_comments)

select user metadata where user not exist.

SELECT * FROM wp_usermeta WHERE user_id NOT IN
 (SELECT ID FROM wp_users)

Delete metadata where users not exist.

DELETE FROM wp_usermeta WHERE user_id NOT IN
 (SELECT ID FROM wp_users)
FacebookTwitterGoogle+RSS