In the WordPress database table wp_term_taxonomy
, each row almost always has the same value for the two columns term_taxonomy_id
and term_id
. What is the difference between these two columns?
Background Terminology
taxonomy
A way to group posts in WordPress (e.g. ‘Categories’ or ‘Tags’ ) See WordPress Taxonomiesterm
One of the groups in a taxonomy (e.g. each of the following might be a term associated with a blog post: ‘Funny’, ‘Political’, ‘Satire’)
History of Shared Terms
Shared Terms
For a long time if you used the same term name in two different taxonomies, WordPress created only one instance of the term. This was called a shared term and ultimately it cause a bunch of problems (See WordPress core ticket 5809).
For example if your blog had both a category and a tag called Funny
and you decided to change the tag to Laugh
, you would expect to have:
- Category:
Funny
- Tag:
Laugh
However, since the term was shared across taxonomies changing the tag to “Laugh” would also change the category:
- Category:
Laugh
- Tag:
Laugh
We can see how a term was shared by looking at the database. Even though “Funny” appears in two different taxonomies, it only appears once in the wp_terms database table.
wp_terms
term_id | name | slug | term_group |
---|---|---|---|
1 | Funny | funny | 0 |
2 | Political | political | 0 |
3 | Satire | satire | 0 |
wp_term_taxonomy
When a term was shared the same term_id
would appear more than once in the wp_term_taxonomy table.
term_taxonomy_id | term_id | taxonomy | description | parent | count |
---|---|---|---|---|---|
1 | 1 | category | 0 | 1 | |
2 | 1 | post_tag | 0 | 1 | |
3 | 2 | category | 0 | 1 | |
4 | 3 | category | 0 | 1 |
Term Splitting
In WordPress 4.2 taxonomy term splitting was performed, taking any term that appeared in multiple taxonomies and making a separate copy of it in wp_terms. (Note: “Funny” now appears twice, as term_id 1 and 4)
wp_terms
term_id | name | slug | term_group |
---|---|---|---|
1 | Funny | funny | 0 |
2 | Political | political | 0 |
3 | Satire | satire | 0 |
4 | Funny | funny | 0 |
wp_term_taxonomy
term_taxonomy_id | term_id | taxonomy | description | parent | count |
---|---|---|---|---|---|
1 | 1 | category | 0 | 1 | |
2 | 4 | post_tag | 0 | 1 | |
3 | 2 | category | 0 | 1 | |
4 | 3 | category | 0 | 1 |
The Future
No one can know what decisions will be made about the taxonomies in WordPress in the future but this discussion from 2015, Potential roadmap for taxonomy meta and post relationships, proposes the idea of adding the term name
and slug
to the wp_term_taxonomy table and removing the wp_terms table entirely.
Leave a Reply