I would like to remove all users from WordPress site using WP CLI except one (me, as administrator).
This command remove every user:
wp user delete $(wp user list --field=ID --number=10)
Unfortunately (or not), nobody have any role except the administrator. So I cannot filter based on this information.
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