Deleting Massive Amounts of Comments in Wordpress

2009 February 21
by kevin

If you are like me and neglected your wordpress blog for a ridiculous amount of time you probably have a ridiculous amount of comments awaiting moderation. Unfortunately, wordpress only displays 20 comments per page so processing 10,000+ spam comments will take forever! And clicking on “Check For Spam” doesn’t seem to be able to handle massive amounts of pending comments. Therefore, after spending a couple of hours deleting comments 20 at a time I decided to find a better way.The following only works if you have access to your server or can log into the database with a mysql client:

First, you should back up the wp_comments table in case anything goes wrong:

# mysqldump -u [username] -p --single-transaction [database name] wp_comments > wp_comments.sql

Then you can log into the database and delete pending comments on mass:
# mysql -u [username] -p [database name]
mysql>delete from wp_comments where comment_approved = 0 and comment_content like '%viagra%';

Notice the “viagra” part? Just do a quick audit of your pending comments and look for obvious spam content. Stick any string of characters from the spam in between the “%” symbols and you will make quick work of thousands of spam comments. Just keep repeating the delete statement. The goal is to get it down to a reasonable number so that you can get Akismet to do the rest by clicking on “Check For Spam”.

Note that I did this with version 2.7.1 of Wordpress.

7 Responses leave one →
  1. 2009 March 26

    Try #2 to leave a comment. I keep getting wp-comments-post.php as a download.

    If you’re already using Akismet, why not just do a check against “comment_approved” being set to spam?

  2. 2009 March 29
    RaiulBaztepo permalink

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  3. 2009 June 8

    а ты интересно постите ролики впроекте?

  4. 2009 June 15
    no can do.. permalink

    I’m using a different template, so I think that is why this cannot be done.. i came up with the following:

    Deleted rows: 0 (Query took 0.0003 sec)

    Hmmm.. why?
    I using a review type of theme.

    Any other methods?

  5. 2009 June 25

    I don’t play around a lot in WP but I can imagine if you have a different template for the admin interface (does such a thing exist?) it could ruin my recipe.

  6. 2009 June 25

    Sorry I don’t speak nor read Russian.

  7. 2009 September 3

    Cool site, love the info.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS