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 termmeta and how to clean them?

Younes JFR.

What are duplicated termmeta?

WordPress terms, such as categories and tags, can store metadata in the wp_termmeta table. Duplicated termmeta entries occur when multiple rows share the same term_id and meta_key, often created by plugins that improperly save taxonomy-related data multiple times.

How they affect your database?

Duplicated records in the wp_termmeta table waste database space and can slow down taxonomy-related queries. They also make your data inconsistent and increase backup or export times unnecessarily.

How to clean them?

1. Using Advanced Database Cleaner plugin

You can safely delete duplicated termmeta using the General Cleanup module in Advanced Database Cleaner plugin.

This approach is smart, automated, and safe. It allows you to:

  • Identify and remove duplicated termmeta records.
  • Schedule automatic cleanups to maintain long-term database health.

2. Using a raw SQL query

If you prefer the manual method, you can execute this SQL command in phpMyAdmin for example:

DELETE tm1 FROM wp_termmeta tm1
INNER JOIN wp_termmeta tm2 
WHERE 
    tm1.meta_id > tm2.meta_id 
    AND tm1.term_id = tm2.term_id 
    AND tm1.meta_key = tm2.meta_key;

In multisite environments, you need to run the query separately 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 termmeta, 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.