Black Friday - Cyber Monday Sale
30% OFF All Premium Licenses
  • 00 Days
  • 00 Hrs
  • 00 Mins
  • 00 Secs
Use code
SIGMA30

This 30% discount applies only to the first year. From the second year, renewals are charged at the regular price.

What are WordPress spam comments and how to clean them?

Younes JFR.

What are spam comments?

Spam comments are unwanted or irrelevant comments automatically filtered or manually marked as spam in WordPress. They’re often generated by bots or spammers and can quickly accumulate, especially on popular websites that allow commenting.

How they affect your database?

Spam comments are stored in the wp_comments table with the status spam. Even though they’re hidden from your site, they still take up space and can slow down operations such as database queries, backups, or exports if not cleaned regularly.

How to clean them?

1. Using Advanced Database Cleaner plugin

You can easily remove spam comments using the General Cleanup module in Advanced Database Cleaner plugin.

This method is safe, flexible, and can be fully automated. You can customize the cleanup to:

  • Delete all spam comments or keep only those created within the last X days.
  • Use the Keep Last feature to retain a limited number of comments if necessary.
  • Schedule automatic cleanups so spam comments are removed regularly without manual effort.

2. Using a raw SQL query

If you prefer a manual method, you can run this SQL query directly from phpMyAdmin for example:

DELETE FROM wp_comments WHERE comment_approved = 'spam';

In a multisite setup, you must execute the query for each subsite, replacing wp_ with the subsite’s table prefix (for example, wp_2_, wp_3_, etc.).

Note:
While you can manually run these SQL commands to clean spam comments, we strongly recommend using the Advanced Database Cleaner plugin.
It uses WordPress’s internal cleaning methods, automatically handles multisite installations, and ensures that all related data is safely removed while keeping your database consistent and stable.