The difference between term_id and term_taxonomy_id

The Codex says:

  • term_id is the ID of a term in the terms table
  • term_taxonomy_id is a unique ID for the term+taxonomy pair

What does this mean?

A term is a word. It can belong to a taxonomy, such as tags, categories, or a custom taxonomy. The thing is: there can be several taxonomies containing the same term.

Let’s say you have a term called “fattening“. This word has an id number. This is the term_id. It doesn’t depend on how this word is used, i.e. in which taxonomies the term appears.

Now the word “fattening” as a post tag also has a number. This is the term_taxonomy_id. It corresponds to “the post tag ‘fattening’“.

Maybe you also have a category called “fattening”. While the term_id is the same, the term_taxonomy_id for “the category ‘fattening’” is different.

Got it? Simple. Or maybe not. That’s the way it is, anyway.

If this post was helpful, please let me know in the comments!

Advertisements
Tagged , ,

One thought on “The difference between term_id and term_taxonomy_id

  1. Dan Jones says:

    This is not true, at least not anymore.

    If you have two terms in different taxonomies with the same name, they will have different term_ids.

    Both term_id and term_taxonomy_id are unique for each term/taxonomy pair, since each term (in each taxonomy) has a separate row in the terms table.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: