If you have a lot of spammy comments on your WordPress blog that takes forever to remove through the WordPress dashboard, because it's like hundreds of thousands, maybe even millions of spammy comments, there is a faster way to do it.
For a quick way to purge comments you have not approved or have marked as spam, you can perform a quick query directly from phpMyAdmin in your cPanel hosting account.
Step-by-Step Instructions:
- Log in to cPanel and open phpMyAdmin.
- Select your WordPress database from the left sidebar.
- Click on the SQL tab at the top.
- Paste and execute the following SQL code:
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
Code: Please login/register for access
What this does:
- comment_approved = '0' deletes pending/unapproved comments.
- comment_approved = 'spam' deletes comments flagged as spam.
- comment_approved = 'trash' deletes items in the comment trash.
- Cleans wp_commentmeta first so you don't leave unattached rows taking up database space.
Pro Tip:
Make sure your database table prefix matches! If your prefix is customized (e.g., wp_custom_ instead of wp_), adjust wp_comments and wp_commentmeta accordingly. Taking a quick database export/backup before running mass deletes is always a safe habit!
Deleting hundreds of thousands of unapproved spam comments will instantly shrink your database size, free up server resources, and resolve slow SQL_CALC_FOUND_ROWS queries caused by comment checks.
Hope it helps!
If you've got any questions, just ask!