How to Delete Spam & 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.

49 Comments - Write a Comment

  1. Chresten 5 years ago
  2. Jasom Dotnet 6 years ago
    • Allen 6 years ago
    • Abdullah 4 years ago
  3. Random 6 years ago
  4. Beno Baars 7 years ago
  5. William Hamilton 7 years ago
  6. Fanne 7 years ago
  7. Adrian 7 years ago
  8. Gerald 7 years ago
  9. Paul 8 years ago
  10. Jessica Nunemaker 9 years ago
  11. Larry Naigists 9 years ago
  12. Heather 9 years ago
  13. brian 9 years ago
  14. irene dietrich 10 years ago
  15. Aileen APWLD 11 years ago
  16. whytewolf 12 years ago
  17. Swapnil Thakkar 12 years ago
  18. Sidse 12 years ago
  19. Shizushi 12 years ago
  20. Fernanda Prevedello 13 years ago
  21. fraser 13 years ago
  22. Q 13 years ago
  23. nikhil 13 years ago
  24. Fernando Davila 14 years ago
  25. jim 14 years ago
  26. Willie 14 years ago
  27. Kerry 14 years ago
  28. gloriasetiadi 14 years ago
  29. ali veli 14 years ago
  30. one 14 years ago
  31. EnKrypt 14 years ago
  32. Martin 15 years ago
  33. Aravind 15 years ago
  34. Azian 15 years ago
  35. Patrick Daly 15 years ago
  36. SoItsComeToThis 15 years ago
  37. Adlina 15 years ago
  38. max 15 years ago
  39. brayden 15 years ago
  40. John 15 years ago
  41. Samuel 15 years ago
  42. Decent60 15 years ago
  43. Saqib 15 years ago
  44. Mattehw Maltby 15 years ago
  45. TCzzz 15 years ago
  46. Ali Hussain 15 years ago
  47. Mark 15 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 contact us directly.