Delete WordPress Comments using MySQL Queries

One of the great features of WordPress is the ability to enable comments on posts. This can give users the opportunity to engage with the content and provide valuable feedback. However, this feature can also be abused by spammers who post irrelevant and inappropriate comments.

In order to keep the comment section clean, it is important to delete unwanted comments. While WordPress offers a user-friendly content management system, it can be difficult to delete comments manually.

Spam comments in WordPress are a real problem. There are tons of themes daily. Fortunately, there is a way to use MySQL queries to quickly and easily delete WordPress comments. If you want to delete those comments, here are some useful MySQL queries for you.

Delete all comments

$query = "DELETE FROM {$wpdb->prefix}comments";

Delete unapproved comments

$query = "DELETE FROM {$wpdb->prefix}comments WHERE comment_approved = '0'";

Delete Spam comments

$query = "DELETE FROM {$wpdb->prefix}comments WHERE comment_approved = 'spam'";

Delete Trash comments

$query = "DELETE FROM {$wpdb->prefix}comments WHERE comment_approved = 'trash'";

Delete unapproved comments for which the URL field has a link

$query = "DELETE FROM {$wpdb->prefix}comments WHERE comment_approved != '1' AND comment_author_url != ''";

There are comments’ content has links (a tag). Most of them are spam for sure.

$query = "DELETE FROM {$wpdb->prefix}comments WHERE comment_approved != '1' AND (comment_content like '%http://%' or comment_content like '%https://%')";

Use these queries in the code

global $wpdb;
//get $query from one above

I made a plugin for this purpose. You can download it here.

Leave a Comment

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

Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.