Comments spam and trackback spam is nothing new to any WordPress user. There are many anti spam WordPress plugins out there, which helps us to lower down the number of spam comments on our blog. It doesn’t matter what method we use, spammers always find a new alternate way to add spam comments. One thing which I have usually noticed on my blog is, spammers usually find few specific posts from our blog, and use it for adding spam comments. I use a combination of Akismet + G.A.S.P plugin to beat comment spam, and it works great.
Recently, I disabled G.A.S.P, plugin from WordPress setup blog, and my 2 specific posts of my blog, starts getting tons of comments. Since, I have made my comment settings to be manually approved, none of these comment made into the live site, and despite of escaping Akismet spam detection technology, they all landed in pending comment section. One of the post got almost 600+ unapproved spam comments, and one way to delete them is by manually selecting all comments and trash them.
Instead of taking that route, I decided to find a WordPress SQL query, which will let me delete all comments from a specific post.
Here is the SQL query:
UPDATE wp_comments SET comment_approved='trash' WHERE comment_post_ID=@x;
replace @x with actual post ID
You can hover your mouse on edit post link, to find the post Id. Do remember, this SQL query will delete all comments from the post, so if you have some genuine comments, you might like to take the manual route. Don’t forget to take a backup of your WordPress DB, before using this or any other SQL query.
I hope this specific query will be handy for you in certain cases. If you find this SQL query helpful, do consider giving us a vote on Google plus and Twitter.