WordPress Admin

Delete WordPress Comments By Date

Delete Comments by DateSometime ago i deleted many non essential plugins to try and speed up my site and accidentally included Akismet.

I’m not sure how this happened but for some reason i received about 1000 spam comments that became automatically approved.

Some of my readers have pointed out that this isn’t a good look so i thought i’d work out how to remove them without having to remove all legitimate comments as well.

I did remove over 100 of them manually which took some time however i thought it better to find a solution which i could also write about and share on this blog.

WordPress doesn’t provide any feature within the core functions to delete comments by date so i’ve been running different MySql Database queries in PhpMyAdmin and worded out a solution.

Caution: Always create a database backup or export your database tables before running MySQL Database queries in PhpMyAdmin

A safe way to test these database queries is to import your database backup into a demo or test site and play around with it there. You can then export the database and import it into your primary installation.

Deleting Comments Using MySQL Database Queries in phpMyAdmin

Run the following query in phpMyAdmin after you change the dates to your own unique times.

DELETE FROM `wp_comments` WHERE `comment_date` BETWEEN '2010-03-25 00:00:00' AND '2012-03-28 00:00:00';

You’ll also need to run another query to clean up the meta data in wp_commentmeta

SELECT * FROM `wp_commentmeta` WHERE `comment_ID` NOT IN (SELECT `comment_ID` FROM `wp_comments`);

Deleting Comments Manually in phpMyAdmin

As you can see from the screenshot below, you can easily select rows of 30 comments at a time and delete comments that way.

phpMyAdmin wp_comments
Click To Enlarge

Couldn’t find a plugin to do this so maybe its an idea for someone who understands MySQL Database tables, PhpMyAdmin and has already created WordPress plugins.

If you know of an easier way to delete different types of WordPress comments by date, please share this information with us in the comments. Thanks.

2 replies on “Delete WordPress Comments By Date”

Hi Brad –

I ran into a similar situation and basically did the same thing (with regards to comments).

One ‘issue’ that I am looking for an elegant solution for revolves around deleting plugins. I like to play around with different plugins for a while, and they generally will later get deleted.

However, deactivating and deleting the plugin does not get rid of all traces of the plugin as there are still some rows that are in the database. In some cases, the plugin actually created tables which stay behind!

Have you seen anything to help clean it up?

Be Well.

Hi Paul

Excellent question.

I have tried hundreds of plugins and even though WordPress says it will delete all data after deleting the plugin, it doesn’t so my database has rows left which take up space.

Let me know if you find a solution and i’ll gladly write a full post on it. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *