Deleting thousands of spam blog comments in WordPress

Last week, I ran a small test to publish thousands of blog posts on a single WordPress website. It was more or less a test of strength for exploring the WordPress REST API using Python. These blog posts started to trigger a lot of web scrapers that are looking to leave spammy blog comments. Before I knew it, I had thousands of spam comments that needed to be removed.

In this blog post:

  • Remove thousands of spam blog comments using phpMyAdmin
  • Disable comments on thousands of posts with a single SQL command (also in phpMyAdmin)

Initially, I wanted to tackle this problem with Python. I knew I’d have to connect to WordPress with XMLRPC if I wanted to make any changes directly to my blog posts and their settings. But then I remembered that WordPress saves their blog comments in the database. If I could just access the table using phpMyAdmin, I could just wipe the entire table.

Looking at blog comments in phpMyAdmin.

Let’s just go ahead and empty this bad boy. Head over to the operations tab at the top and scroll down to the bottom. Click Empty the table and you’re done.

The comments keep flooding my inbox, though. I still need to turn off comments for each post. This can also be done in phpMyAdmin. First, we need to find the ID for comments status. In this case, it’s called comment_status. For each post, its set to “open”.

The easiest way to turn off comments for thousands of posts is to go into the SQL tab of phpMyAdmin and updating the posts table to set all comments to closed.

Leave your thoughts below. Follow on Twitter