Remove all users from site except one using WP CLI

Found out you can pass the --exclude option to wp user list to exclude a user by their ID from the list. So let’s assume your user ID is 2 then you could do the following:

wp user delete $(wp user list --field=ID --exclude=2)

And just to be sure all content gets reassigned to you that would be the following command.

wp user delete $(wp user list --field=ID --exclude=2) --reassign=2

Leave a Comment