3 Ways to Remove All Spam and Pending Comments in WordPress

Although there are many different content management systems available to use, WordPress remains one of the most popular today and has won a couple of awards such as the Critic’s Choice Best Open Source PHP CMS and People’s Choice Best Free CMS in 2014. When many websites uses the WordPress platform, this will obviously attract spammers in creating a tool that can automatically spam links to the comment area in a post.

While there are also many antispam plugins to block comment and trackback spam, Akismet remains the top plugin being used to detect spam comments. However these antispam plugins are not perfect as there are times when a spammer finds a way to bypass antispam detection and manage to slip through a few spam comments. Other than that, an unhappy visitor might use these tools to flood a website with thousands of useless comments in hoping to overload the server and causing it to crash.

If one day you wake up to find thousands of spam or pending comments in your WordPress admin area, do not be afraid because there are easy ways to quickly delete the comments. If the spam comments keeps coming in, you should first configure your website to stop accepting any comments. Login to WordPress admin, go to Settings > Discussion. Tick the “Users must be registered and logged in to comment” checkbox ad click the Save Changes button. Then go to Settings > General and make sure that the “Anyone can register” checkbox is uncheck. This two combination settings will prevent any visitor from being able to post comment on your website. We’ll start to clean up the pending or spam comments once this is done. Here we have 3 different ways to delete all WordPress spam comments.

1. Built-in method

WordPress has a built-in method to easily and quickly remove all spam comments. Go to Comments, click on Spam and you will find a Empty Spam button. Clicking on that button will instantly delete all the comments that are flagged as spam.

wordpress empty spam

There are two possible problems in using the built-in Empty Spam feature. If your website is hosted in an underpowered shared server, the empty spam process might time out and even possibly cause the web server software to crash if you are attempting to remove tens or hundreds of thousands of spam comments. Another possible problem is if the comments aren’t being flagged as spam and appears in Pending, there is no button that can allow you to delete all pending comments.

2. Batch Comment Spam Deletion

If you are facing the above problem where the Empty Spam process is timing out due to large amount of comment spam, you can install a plugin called “Batch Comment Spam Deletion”. This plugin simply modifies the Empty Spam action to delete the spam messages in batch rather than all at once. To install the plugin in your WordPress website, go to Plugins > Add New > search for Batch Comment Spam Deletion at the top right box, and click Install Now button.

install batch comment spam deletion

There is nothing else to do after installing the Batch Comment Spam Deletion plugin. It automatically modifies the action of the Empty Spam button. If your server is still timing out after installing this plugin, you will have to reduce the number of spam comments to process. From the source code, it shows that this plugin process 100 spam comments at a time and this can be changed by adding a filter in functions or by adding a constant to your wp-config.php. Another quick and easy method is by directly editing the plugin file from Plugins > Installed Plugins > click Edit for Batch Comment Spam Deletion, change the value 100 to a lower number and click Update File button.

edit batch comment spam deletion

Download Batch Comment Spam Deletion

3. SQL Command

Using the SQL command is very powerful because you can probably delete all spam or even pending comments in less than a second without time out. However, it is a bit risky because a wrong command can empty a table or even worse, wipe out the whole database. So it is advisable to at least create a full backup of your database using a really easy to use plugin such as “Dropbox Backup & Restore“. After installing the Dropbox Backup & Restore plugin, click on Dropbox Full Backup from the top left bar and click “Create Local Backup” button. If anything goes wrong with the SQL command, simply click the “Restore” button.

You will probably find a lot of examples on other websites telling you to use phpMyAdmin to do it but we think that is a bit overkill because not all web server has phpMyAdmin installed and selecting the wrong database might end up cleaning the comments for other websites hosted at the same account. An easier and safer solution is to install another plugin called SQL Executioner that allows you to execute SQL queries for the WordPress website that it is ran from.

To install, go to Plugins > Add New > type SQL Executioner in the search plugin box located at the top right, and click “Install Now”. After finished installing and activating the plugin, go to Tools > and select SQL Executioner. Click the $comments link to describe the comments table and take note of the table name.

describe comments

Most of the time the default name of the comments table is wp_comments. You can confirm this by checking the name of the comments table after clicking the $comments link. Now here are a few different SQL commands to delete all spam or pending comments.

To remove all pending comments:

DELETE FROM wp_comments WHERE comment_approved = "0"

To remove all spam comments:

DELETE FROM wp_comments WHERE comment_approved = "spam"

Type the command in the SQL box and click “Execute SQL” button. Click OK button to confirm the query to modify data in your database. The number of rows affected shows the number of comments being removed from database.

38 Comments - Write a Comment

  1. Jessica Nunemaker 12 months ago
  2. Larry Naigists 1 year ago
  3. Heather 1 year ago
  4. brian 1 year ago
  5. irene dietrich 2 years ago
  6. Aileen APWLD 3 years ago
  7. whytewolf 4 years ago
  8. Swapnil Thakkar 4 years ago
  9. Sidse 4 years ago
  10. Shizushi 4 years ago
  11. Fernanda Prevedello 5 years ago
  12. fraser 5 years ago
  13. Q 6 years ago
  14. nikhil 6 years ago
  15. Fernando Davila 6 years ago
  16. jim 6 years ago
  17. Willie 6 years ago
  18. Kerry 6 years ago
  19. gloriasetiadi 6 years ago
  20. ali veli 6 years ago
  21. one 7 years ago
  22. EnKrypt 7 years ago
  23. Martin 7 years ago
  24. Aravind 7 years ago
  25. Azian 7 years ago
  26. Patrick Daly 7 years ago
  27. SoItsComeToThis 7 years ago
  28. Adlina 7 years ago
  29. max 7 years ago
  30. brayden 7 years ago
  31. John 7 years ago
  32. Samuel 7 years ago
  33. Decent60 7 years ago
  34. Saqib 7 years ago
  35. Mattehw Maltby 7 years ago
  36. TCzzz 7 years ago
  37. Ali Hussain 7 years ago
  38. Mark 7 years ago

Leave a Reply

Your email address will not be published. Required fields are marked *

Note: Your comment is subject to approval. Read our Terms of Use. If you are seeking additional information on this article, please ask in our forum or contact us directly.