Query to mass delete members in WordPress

I had a lot of spam members in my WordPress installation (thanks to BuddyPress and it’s horrible system of registration and profile syncing). I would like to run a query to delete all members who have registered in last one month (or any particular time frame).

Then, how to delete the corresponding records from wp_usermeta table too along with deleting records from wp_users table?

Related posts

Leave a Reply

1 comment

  1. DELETE FROM `wp_users` 
    WHERE DATEDIFF(NOW(), user_registered) < 30; -- 30 is the time in days
    

    I would recommend, as with any destructive query, first testing it by replacing DELETE with SELECT *.

    Afterwards clean up meta with:

    DELETE FROM `wp_usermeta` WHERE user_id NOT IN (SELECT id FROM `wp_users`);