12-Mar-2026

Batch Deleting WordPress Users with Filtering

Sometimes there's a need to remove users based on their usernames and other criteria. Learn how to do this with various methods including automatically using WP-CLI.

Using the User List

Deleting users manually is fine with WordPress's user list if you don't have too many screenfuls of them. The user list is accessible from the dashboard and can be filtered. The listed users can all be selected at once and then select Delete from the Bulk actions dropdown and then Apply. A new screen is shown with all the users to be deleted listed. Finally click on the Confirm Deletion button at the bottom of the page. After some time, the user list you started from will be reshown with less users than before.

To delete more users at once change the list size by going to Screen Options at the top right of the page and then change the Number of items per page: option. Deleting any more than 100 at a time will probably cause a time out error and you will have to start again.

For deletion jobs with less than 500 users the user list method is fine, but any more than that and it becomes tedious quickly.

Using a Plugin

There are a number of plugins available for bulk deleting users, but the ones I tried were less useful than the dashboard user list method described above, which provides filtering. None allowed filtering with the free versions. If most users need to go and filtering is not needed, then one of the plugins free versions would be fine.

Using WP-CLI

The WordPress CLI (command line interface) is an excellent way to delete users based on any criteria the wp list command can filter by. It is slow at about 1200 users per hour, but it can be left to run on its own and it could be run in the background on Linux.

Installing WP-CLI

Most web hosting companies running Linux will already have WP-CLI installed. If you run your own server WP-CLI installation is easy by following the instructions at https://make.wordpress.org/cli/handbook/guides/installing/.

Deleting Unwanted Users with WP-CLI

The following commands use WP-CLI to filter the user list. WP-CLI. needs to be run from the folder where wp-config.php is located for the website. Typically, it's at ~/public_html, but your setup may be different.

cd ~/public_html
wp user delete $(wp user list --search="substring_to_match" --field=ID) --reassign=admin_user_id --yes

Or....

wp user list --user_name="1000 USD BONUS" --fields=ID | xargs -n 1 wp user delete --reassign=673 --yes

Upon trying it out many normal users rather than just the spammy "1000 USD BONUS" users were let through to the delete list, which isn't what we want.

Displaying Users to be Deleted

With the previous commands not working too well, before using your filter to delete users it's a wise move to check which ones will be deleted. This can be done with the following command. If the list is too long use less to paginate the printout. The printout also shows the date when the user was set up. If the dates are recent there may be an issue with active spammers.

wp user list | grep "1000 USD BONUS" | less

A more reliable method is to use grep to filter the wp-cli user list, then piped to awk to just pass the user ID to the wp user delete command, as shown below. Reassign the post content to any admin user's ID, which for this case is 673. Optional use of sort is to give you an idea how the list is going as deletions go by on the console.

wp user list | grep "1000 USD BONUS" | awk '{print $1}' | sort | xargs -n 1 wp user delete --reassign=673 

Leave a Reply

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram