Remove WordPress comments from unregistered users
In a WordPress database, unregistered users are categorized with user_id = 0
. You can remove their comments specifically by following these steps.
Warning: Always make a backup of your site before making any changes to the database.
- Sign in to phpMyAdmin.
- In phpMyAdmin, on the left menu, select the name of the database your site uses.
- On the top menu, select SQL.
- In the box below, enter the following code:
DELETE wp_comments, wp_commentmeta FROM wp_comments INNER JOIN wp_commentmeta WHERE wp_comments.comment_id=wp_commentmeta.comment_ID AND wp_comments.user_id = 0; DELETE FROM wp_comments WHERE user_id = 0;
Note: If your table prefix isn't wp_, you should replace all instances of wp_ in this code with your actual table prefix. You can check which prefix your site uses in the wp-config.php file. - Select Go.
All comments from unregistered users are now removed from your site.