Black Friday - Cyber Monday Sale
30% OFF All Premium Licenses
  • 00 Days
  • 00 Hrs
  • 00 Mins
  • 00 Secs
Use code
SIGMA30

This 30% discount applies only to the first year. From the second year, renewals are charged at the regular price.

What are duplicated commentmeta and how to clean them?

Younes JFR.

What are duplicated commentmeta?

Each comment in WordPress can have metadata, known as commentmeta, which stores additional information added by plugins or themes, such as ratings, flags, or custom comment settings. Duplicated commentmeta entries occur when multiple rows share the same comment_id and meta_key, often due to plugin conflicts or redundant saves.

How they affect your database?

Duplicated entries in the wp_commentmeta table can waste disk space and slightly slow down comment-related queries. On sites with many comments, this can contribute to unnecessary database bloat and increase backup or export times.

How to clean them?

1. Using Advanced Database Cleaner plugin

You can easily clean duplicated commentmeta using the General Cleanup module in Advanced Database Cleaner plugin.

This feature is designed to safely detect and delete unnecessary duplicate metadata. You can also:

  • Detect and delete all duplicated commentmeta entries.
  • Schedule automatic cleanups to remove duplicates periodically.

2. Using a raw SQL query

If you prefer the manual approach, you can execute the following SQL command in phpMyAdmin for example:

DELETE cm1 FROM wp_commentmeta cm1
INNER JOIN wp_commentmeta cm2 
WHERE 
    cm1.meta_id > cm2.meta_id 
    AND cm1.comment_id = cm2.comment_id 
    AND cm1.meta_key = cm2.meta_key;

In multisite setups, you need to execute this query for each subsite, replacing wp_ with the corresponding subsite prefix (for example, wp_2_, wp_3_, etc.).

Note:
While you can manually run these SQL commands to clean duplicated 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.