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
$wpdb->query($wpdb->prepare($query));
I made a plugin for this purpose. You can download it here.