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

Younes JFR.

What are unused termmeta?

WordPress stores metadata for categories, tags, and custom taxonomies in the wp_termmeta table. Unused termmeta entries occur when a term (like a category or tag) is deleted, but its associated metadata remains in the database. This often happens when plugins or themes that use termmeta are uninstalled or updated incorrectly.

How they affect your database?

Unused termmeta records add unnecessary data to the wp_termmeta table, increasing your database size and slightly slowing taxonomy-related queries. They can also make backups larger and less efficient.

How to clean them?

1. Using Advanced Database Cleaner plugin

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

The plugin scans for termmeta that are not associated with any existing term and lets you:

  • Delete all unused termmeta entries safely.
  • Automate the cleanup process to keep your taxonomy data optimized.

2. Using a raw SQL query

If you prefer manual cleanup, you can run this SQL query in phpMyAdmin for example:

DELETE tm FROM wp_termmeta tm
LEFT JOIN wp_terms t ON t.term_id = tm.term_id
WHERE t.term_id IS NULL;

In multisite installations, this command must be executed for each subsite, replacing wp_ with the appropriate subsite prefix (for example, wp_2_, wp_3_, etc.).

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