WP-CLI is nothing new to most of the wordpress users or developers. It saves an enormous amount of time when it comes to installing, updating, deleting wordpress updates, plugins, themes, comments – and a lot of other stuffs. If you haven’t been using wp-cli, you have wasted a lof of productive hours in your life. In that case, get a grasp of what wp-cli is.


As we have said it does a hell lot of things, today we’re going to see how we can bulk delete wordpress comments that we no longer wish to be stored in the wordpress database. If you have a high traffic site or a popular blog or a network poster from your blog (for promotion), you might be getting a lot of pingbacks or trackbacks – which will be stored as comments in your wordpress. Now many a times we might not simply want to have them stored and keep them on hold. So we’d need to delete them in bulk. Using wordpress’s UI with paging can be tedious deleting hundreds of thousands of comments. So we need a shortcut – which saves our precious time.


Before we begin to delete the comments, let’s see how many statuses a comment might have in wordpress. They are :

  1. hold
  2. approve
  3. spam
  4. trash


Now as for the first one “hold”, it might be listed as “Pending” in your comments panel in wordpress. Say we have 577 “pending” comments that we want to clean. wp-cli by default doesn’t give a single command which will delete all the comments with criteria. It can list them and delete them separately.


To delete the comments we’d need the IDs of the comments. So first, we list them and then with the IDs we delete them. Actually we delete them passing the list as parameters 🙂

To list the comments which are “pending”

This will give us the IDs one by one per line in the command line output.

Now to delete them with IDs we normally use

Now the magic

This would delete all the comments automatically which are “pending’. You might get the command line output like

And, if you want to clean the trash as well, just change the status of the last command from “hold” to “trash”.

Alrightee, we have saved some minutes (I guess 😉 )


Post Meta

Posted on:
October 30, 2014
2 Responses to “Delete WordPress Comments with WP-CLI”


11:22 pm

Thanks! Chaining them together as:
wp comment delete $(wp comment list –status=hold –field=ID) && wp comment delete $(wp comment list –status=trash –field=ID)
worked great for me as a single command.

Note that using the Cloudflare plugin can cause a lot of error messages to appear in the Terminal when using WP-CLI, and deleting 27,000 comments can be…. “intense”.

Cadu de Castro Alves

12:41 pm

One more tip: if you want to delete in bulks (e.g.: 1000 comments each time), just append –number=1000 to the command.