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
  • 1
    If I need to exclude more then one user I can use something like --exclude=2,3?
    – natas
    Dec 5 '19 at 12:16
  • @natas – Yes, exactly. You can simply try it out yourself with wp user list against wp user list --exclude=2,3,4,5.
    – leymannx
    Dec 5 '19 at 13:15
  • what to add in --field=id May 2 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.