Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - delete all users without role

Tags:

wordpress

spam

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.

like image 611
Morteza Avatar asked Nov 26 '14 00:11

Morteza


People also ask

How do I mass delete users on WordPress?

One method to delete several users simultaneously is by viewing them in the admin panel and then selecting them for deletion. In this method, you don't have to install any new plugins or make major alterations to the website. It's perhaps one of the easiest ways to bulk delete WordPress users quickly.

How do I bulk delete users?

To bulk delete usersOpen the CSV file and add a line for each user you want to delete. The only required value is User principal name. Save the file. On the Bulk delete user page, under Upload your csv file, browse to the file.

Can you delete users in WordPress?

Deleting usersLog in as admin, then navigate to your dashboard. From the dashboard, select Users > All Users. Locate the desired user, then click Delete. Confirm when prompted.

How do I remove a user from a WordPress database?

Upon activation, you need to visit Bulk WP » Bulk Delete Users page. Here you can select Bulk Delete options for deleting users. First, you can select the specific user roles. After that you can select the filtering options.


1 Answers

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)
like image 157
lord_viper Avatar answered Sep 27 '22 22:09

lord_viper