delete all comments from a specific post

delete all comments from a specific post

In this tutorial we are going to look at ways to delete all comments from a specific post on WordPress. Getting rid of spam comments is one of the major concern every WordPress blog owner has. It is usually seen that spammers spam some specific post of yours which is generally an old one. In such scenarios, you would need to delete all comments on your post so that your website’s ranking doesn’t take a hit because of spam comments.

One of the way is to go through all the comments on that post and click on trash icon against all the comments. This is feasible and the recommended way if you have like 10-20 comments. However it becomes a real pain if you have like 200+ comments on that post. Clicking on trash icon for all those 200+ comments is not at all a practice solution to our problem in hand.

The solution we are now going to discuss involves running SQL Queries on your WordPress database. As a thumb rule, it is recommended to take a full backup of your WordPress database before proceeding with SQL Queries. This should be done so as to restore the database just in case you end up doing some irreversible damage to your database. To take a backup, there are a lot of readymade plugins available like WP-DB-Backup which you can use. Otherwise you can also manually take backup of your database using below steps :

1: Login to phpmyadmin

2: Select the database and click on export

3: Select all the tables as we need to take a full backup of Database.

4: Select SQL as we want to export the database tables as .sql file

5: Click on “Save as File”

6: Click on “Go” button which will download a .sql file.

Once you have taken a backup, we are all set to use SQL Queries to delete all comments from a specific WordPress post.

Step 1: First step is to get the ID of the post whose comments you need to delete. For that run the below SQL Query, which will return you the ID of your post.

SELECT ID from wp_posts WHERE post_type=’post’ AND post_title=’Hello world!’

Please note that you need to change the “Hello world!” in the above script with the title of your WordPress Post.

Alternatively, you can also get to know the post ID by hovering your mouse over edit post link.

Step 2: Once you have the ID of the post, we just need to run the below SQL Query to delete all the comments on that post.

UPDATE wp_comments SET comment_approved=’trash’ WHERE comment_post_ID=POST_ID;

In the above query, replace the “POST_ID” with the ID of the post which you got in the previous step.

So by using the simple SQL Query explained above, you can delete all the comments on a specific WordPress post in one go. There could be cases when you have a lot of genuine comments too on your post and you don’t wish to delete them. In that case you would have to take the manual route to delete each spam comment. I just hope that such situation doesn’t come up.

Alternatively, if there is one specific spam user who has posted comments on your blog, you can use the WordPress plugin “Delete Comments”. This plugin lets you delete comments category wise and user wise.

References:

  1. Delete Comments : https://wordpress.org/plugins/delete-comments/

Also Read:

  1. 8 Essential WordPress SQL Queries
  2. How to delete WordPress Trackback in bulk using SQL Query 

I hope this article will help you to delete all comments from a specific post in WordPress. Keep sharing this article with your friends and hit the like button on our Facebook, Twitter and Google+ profiles.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

1 + 1 =