WordPress – delete all users without role

We have more than 900.000 spam users! and they haven’t any role. We want to delete all spam users and their meta.

In this answer and this link we can delete users based on role but our spam users doesn’t have any role.

Read More

This query return real users:

SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities'

In usermeta spam users doesn’t have capabilities key.

We want remove spam users with database query.

Related posts

Leave a Reply

1 comment

  1. for resolve you can use subquery and in operator

    delete from wp_users where ID not in
    (select user_id from wp_usermeta where meta_key = 'wp_capabilities')
    
    select user_id from wp_usermeta where user_id not in
    (select ID from wp_users)