Delete all pending comments at once

If you are presented with a new website with thousands or millions of pending comments and if you know that all pending comments are actually spam comments, you’d want to quickly get rid of all such comments before you do anything further on that site to speed-up your actual workflow. Here’s a quick tip to delete all pending comments.

wp comment delete $(wp comment list --status=hold --format=ids) --force

Word of warning: Never execute any random command found on the internet. NEVER.

Explanation:

Before executing the above command, lets break it up and understand what’s going on.

wp comment list --status=hold --format=ids

The above command creates a list of IDs (of comments) that are under moderation queue (pending).

wp comment delete $(wp comment list --status=hold --format=ids)

The above command will send all the pending comments to trash. Any comment in trash is usually get deleted automatically after 30 minutes. If you’d like to delete a comment permanently skipping trash, then we can use --force flag.

Leave a Reply

Your email address will not be published. We use cookies to prevent spam comments. Required fields are marked *