What are unused commentmeta?
WordPress stores comment-related metadata in the wp_commentmeta table. These data entries contain additional details added by plugins or themes, such as ratings, flags, or moderation notes. When comments are deleted or a plugin is removed, some commentmeta entries can remain in the database without a valid parent comment – these are considered unused commentmeta.
How they affect your database?
Unused commentmeta entries bloat the wp_commentmeta table, wasting disk space and slowing down queries related to comments. They also increase the size of backups and exports, especially on sites that receive a lot of user interaction or spam comments.
How to clean them?
1. Using Advanced Database Cleaner plugin
You can easily clean unused commentmeta using the General Cleanup module in Advanced Database Cleaner plugin.
The plugin automatically detects commentmeta entries that no longer belong to existing comments and lets you:
- Delete all unused commentmeta safely.
- Automate the cleanup process to keep the database optimized.
2. Using a raw SQL query
If you prefer a manual method, you can run this SQL query in phpMyAdmin for example:
DELETE cm FROM wp_commentmeta cm LEFT JOIN wp_comments c ON c.comment_ID = cm.comment_id WHERE c.comment_ID IS NULL;
In multisite installations, you must execute this command for each subsite, replacing wp_ with the subsite’s prefix (for example, wp_2_, wp_3_, etc.).
Note:
While you can manually run these SQL commands to clean unused commentmeta, 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.