type in your query to search makeyougohmm
Things that ... make you go hmmtechnology music video art news reviews and muse on the web

December 7, 2006

How to identify and remove Wordpress comment spam MySQL queries

blogs and podcasting, spam, How To — by TDavid @ 8:15 pm PST
F = please no more posts like thisD = not among your best stuffC = average postB = good post, I liked itA = great post, please create more like this (1 votes, average: 1 out of 5)
Loading ... Loading ...

MySQL command line for checking wordpress comments approved

If you are using the default database configuration of Wordpress, then here’s a command line MYSQL query — also works in programs like PHPMyAdmin — to see what the breakdown is of approved, spam and waiting comments:

select count(comment_ID), comment_approved from wp_comments group by comment_approved;

This will return a query that looks like what’s pictured and highlighted at the top of this post. These are the codes:

0 = pending comments
1 = approved comments
spam = comments you’ve marked as ’spam’ or deleted.

For some strange reason comments aren’t actually deleted in the Wordpress database when marked ‘delete’. I didn’t look in the code to see why this is being done this way, but to me when you delete something that means it actually gets deleted, not saved in the database in the spam bin. Perhaps there is a good reason why the Wordpress team is doing this but you don’t need to keep these deleted/spam comments unless you want to use them to detect spam patterns or abuse.

Assuming you don’t want to keep those comments, here is the code to clean out the spam comments from the wp_comments table in Wordpress:

delete from wp_comments where comment_approved = ’spam’;

Voila. You will now have a Wordpress-powered blog clean of spam/deleted comments. The busier your blog, the more these comments will start adding up so might want to set some sort of cron job that wipes out these comments once a week, month, whatever.

Related Posts

RSS Feed comments for this post 1 Comment »

  1. Hey thanks for this! By the way, what about wp_postmeta? My file is 11MB now…

    Comment by davido — July 8, 2007 @ 7:37 am PST


TrackBack URI: http://www.makeyougohmm.com/20061207/4025/trackback/

Leave a comment


By leaving a comment you consent to the Official Hmm Comment Policy

Return Home


Copyright 2003-2008 KMR Enterprises All Rights Reserved