Wordpress - delete all users without a role

We have over 900,000 spam users! and they do not play any role. We want to remove all spam users and their meta.

In this answer and this link, we can delete users based on the role, but our spam users have no role.

This query returns real users:

SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities'

In usermetaspam users do not have a key capabilities.

We want to remove spam users with a database request.

+4
source share
1 answer

for permission, you can use the subquery in the statement

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)
+4
source

All Articles