The title says it all. At the moment in my custom taxonomies I'm getting the terms using the term id and taxonomy name.

Thought this question would've been asked before but can't find it anywhere! So just thought I'd ask and see if anyone has any answers.

5 Answers 5


If you take a look into the Wordpress documentation you will find Wordpress Taxonomies

  • term_id is the ID of a term in the terms table
  • term_taxonomy_id is a unique ID for the term + taxonomy pair.
  • so manipulating and grabbing terms based only on the term_id wouldn't cause duplicates then?
    – Daithí
    Commented Jan 2, 2012 at 18:51
  • 2
    actually just answered that last question. Had a look at the wp_terms table and yep using the term_id only is safe. Thanks for your reply @Juan
    – Daithí
    Commented Jan 2, 2012 at 18:55
  • 5
    Just a note that in WordPress 4.2 all terms were split, meaning that each term_id will now occur only once in the term_taxonomy table (before the column wasn't unique and terms could be shared across taxonomies). This may continue to evolve in future, based on the taxonomy roadmap. One part of that is to combine the term and term taxonomy tables.
    – J.D.
    Commented Apr 19, 2016 at 19:04
  • @J.D. so upsetting that after 8 years those tables are not yet combined Commented Nov 23, 2022 at 9:27

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.


As this is a part of a bigger understanding of the design I will describe it as whole... :)

In WP 4.5.3 there are still all these tables (I will talk about them without prefix):

  • posts
  • term_relationships
  • term_taxonomy
  • terms

The path to get post terms' readable names goes through them all.

the main identificator here is ID - an id of a post (of any type)

stores pairs of:
object_id - can be posts.ID (but does not have to be)
term_taxonomy_id - this is NOT id of a term (category) but an id of RELATIONSHIP between a term(category) and taxonomy("category type")

the main identificator here is term_taxonomy_id desribed above ^^
another important columns:
term_id - an id of a term (category)
taxonomy - stores the term's taxonomy("category type")

This one might seem funny, but the initial intend was to add the ability for terms to have more taxonomies (which in some cases can make sense).

the main identificator here is the term_id - an id of an category
another important columns here are:
name - readable category name e.g. "Music Genres"
slug - the slug of a term usable e.g. in URL

So the brutal demonstrating SQL to
get all published posts and all their categories with categories' names
could look like this (add prefixes to tables when testing on your own WP DB):

posts #gets posts
term_relationships #gets posts relationships to term_taxonomies
term_taxonomy #gets term_ids 
terms #finally, gets terms' names
    #optionally you can filter by a certain post_type:
  • Hands down the clearest explanation on this thread... Thanks! Commented Sep 15, 2021 at 19:09

A term is not a category or tag on its own. It must be given context via the term_taxonomy table.

The term_taxonomy table places a term within a taxonomy. This is what makes a term a category, a tag or part of a custom taxonomy (or in a combination of taxonomies).

term_id is the ID of a term in the terms table.

term_taxonomy_id is a unique ID for the term+taxonomy pair.

The term_id is always unique just like the term_taxonomy_id. Both have an Auto Increment in the table structure.

The table wp_term_taxonomy makes sure for example that a category is created, so wordpress can interfere with it e.g Woocommerce uses: product_tag, product_type, product_cat, all of them are the so called custom taxonomies. This table also binds the parent/children structure. With it's column parent.

The final table, term_relationships, relates objects such as posts or links to a term_taxonomy_id from the term_taxonomy table.

If we pick Woocommerce again as an example, this table links post type products to their taxonomy product_cat, which contains a namy e.g Computers which is of course retrieved from the table wp_terms. This table contains the term_id, name, slug and term_group. (term_group I personally have never used)

Hopefully the above makes things a bit more clear about the differences and how Wordpress uses these tables.


The Article "Understanding and Working with Taxonomies and Terms in WordPress" explains the reason for using two separate tables - wp_term and wp_term_taxonomy:

In many WordPress installations, there will be one record in the wp_term_taxonomy table for each term in the wp_terms table, but in some cases you will have more than one record for each term. This happens when you create two terms with the same name and slug in different taxonomies, and means that you could create a query to output posts with that term in multiple taxonomies.

This means that the relationship between these two tables is one-to-many: one record in the wp_terms table can be linked to multiple records in the wp_term_taxonomy table, but each record in wp_term_taxonomy is only linked to one record in wp_terms.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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