Wordpress - delete all users without role

1.9k Views Asked by At

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.

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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)