Delete all subscribers from wp_users and wp_usermeta a few thousand at a time

My favorite way to do something like this is not via database hacking (which I am always concerned will have side effects), but via a command line tool.

For example, giving a functioning WP CLI install, you can simply do this:

wp user delete $(wp user list --role=subscriber --field=ID --number=10) --reassign=1

The reassign parameter is the user ID of the user to reassign content to. We can use “–number” (the limit), even though it is not well documented, because WP_User_Query supports it.

There you have it – a clean, one line command line utility to do operations like this.

I’d recommend in this case you try the subquery first “wp user list..” to see which users it will delete. After running the one-liner, you will see information like this:

...
Success: Removed user 123 from https://example.com/.
Success: Removed user 124 from https://example.com/.
...

Leave a Comment