I am a PHP developer and recently I am trying to build a platform which needs lots of categories/filters/tags some in hierarchy some not.

So the question is...

I am able to manage terms in these tables terms, terms_metadata and terms_relationships, but there is another table in WordPress - terms_taxanomymy.

What is the significance of defining another table for just storing "parent", "type", "count" and "description" when you can do that in terms table itself.


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.

  • Does this explain (at least, nowadays,) why the values for the term_taxonomy_id and term_id columns in the *_term_taxonomy table always match each other? I've wondered for a while why one of these columns is seemingly redundant. – George Apr 25 '19 at 10:43
  • 1
    @George they’re not exactly redundant, because they’re keys for tables. But yes, if the site was created after 4.2.2, then these IDs should be equal (as every term insert causes an insert in term_tax, so autoincrements for these tables should be the same). If the site was created before that version, then these keys may differ a lot. – Krzysiek Dróżdż Apr 25 '19 at 12:37
  • thanks for the explanation :) – harshit mishra Apr 29 '19 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.