Why WordPress uses 4 tables to manage terms

Well, it uses 3 tables. The fourth one (wp_termmeta) is just a way of allowing you to store some meta values for terms (icons, additional descriptions and so on).

Citing from Codex:

  • wp_terms – The categories for both posts and links and the tags for posts are found within the wp_terms table.
  • wp_termmeta – Each term features information called the meta data and it is stored in wp_termmeta.
  • wp_term_relationships – Posts are associated with categories and tags from the wp_terms table and this association is maintained in
    the wp_term_relationships table. The association of links to their
    respective categories are also kept in this table.
  • wp_term_taxonomy – This table describes the taxonomy (category, link, or tag) for the entries in the wp_terms table.

So the only part that may be confusing is that there are separate tables for terms and term_taxonomy… And it can be confusing, because it has lost its meaning nowadays.

But before WP 4.2.2 (I guess) the approach to terms was a little bit different – terms were unique across wp_terms table.

So if you had “books” as category and “books” as tag, then there was only one record with “books” in wp_terms and obviously 2 records in wp_term_taxonomy.

But when the wp_termmeta table was introduced it would make it confusing – so such terms were split. And today, for the example above, you’ll have two separate rows in wp_terms table.