2

I have 20,000 fake subscribers I'd like to get rid of. The admin panel only lets you delete 200 at a time.

How can I bulk delete all Wordpress subscribers via MySQL?

4 Answers 4

3

I ended up deleting all users who had not made a post using the following two queries:

First:

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

Second:

DELETE
FROM wp_usermeta WHERE user_id NOT IN
(SELECT ID FROM wp_users)
2

You can use :

<?php
$blogusers = get_users( 'role=subscriber' );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
    $user_id = $user->ID;
    wp_delete_user( $user_id );
}
5
  • in functions.php? Apr 22, 2017 at 19:49
  • If you run query for once then you can use in functions.php with if( isset($_GET['remove_user'])){ // Here add code } Now call site url like : site-url.com/?remove_uesr Apr 22, 2017 at 19:50
  • like this way: siteurl.com?remove_user ? Apr 22, 2017 at 19:52
  • Once you delete subscriber you can delete script. Apr 22, 2017 at 19:52
  • 1
    siteurl.com/?remove_user Apr 22, 2017 at 19:53
0

I know that this was asked a long while ago, but, if you happen across this like I did, this could help. Running this SQL in phpMyAdmin will remove all subscribers in a WordPress database.

DELETE wp_users, wp_usermeta
FROM wp_users
LEFT JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
WHERE wp_usermeta.meta_key = 'wp_capabilities'
AND wp_usermeta.meta_value LIKE '%subscriber%'

Replace wp_ with whatever your table prefix is. I ran something similar to remove customers and it worked in seconds.

0

Just joined Stack Exchange, so I'm not allowed to upvote someone's comment yet, but SYPOMark's SQL worked like a charm for me. I had thousands of likely spam subscribers. It's always good to make a quick backup of relevant database tables first, just in case something goes very wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.