最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Why WordPress uses 4 tables to manage terms

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Apr 25, 2019 at 5:11 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Apr 25, 2019 at 4:43 harshit mishraharshit mishra 313 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

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.

发布评论

评论列表(0)

  1. 暂无评论