WordPress 中文文档
WordPress Taxonomy
From WordPress Chinese
WordPress 2.3 introduces a new taxonomy schema. Any plugin that queries against the old WordPress 2.2 table will break horribly. Plugins that use the category API should be fine.
This new schema replaces the categories, post2cat, and link2cat tables with three new tables that are more flexible.
- wp_terms
- wp_term_relationships
- wp_term_taxonomy
wp_terms
The first table is the terms table. It holds the basic information about a term.
term_id bigint(20) NOT NULL auto_increment, name varchar(55) NOT NULL default '', slug varchar(200) NOT NULL default '', term_group bigint(10) NOT NULL default 0, PRIMARY KEY (term_id), UNIQUE KEY slug (slug)
-
nameis simply the name of the term. -
slugis the name reduced to a URL friendly form. -
term_groupis a means of grouping together similar terms. -
term_idis a unique ID for the term.
wp_term_taxonomy
A term is not a category or tag on its own. It must be given context via the term_taxonomy table.
term_taxonomy_id bigint(20) NOT NULL auto_increment, term_id bigint(20) NOT NULL default 0, taxonomy varchar(32) NOT NULL default '', description longtext NOT NULL, parent bigint(20) NOT NULL default 0, count bigint(20) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), UNIQUE KEY term_id_taxonomy (term_id,taxonomy)
The term_taxonomy table places a term within a taxonomy. This is what makes a term a category or tag (or both).
-
term_idis the ID of a term in the terms table. -
taxonomydesignates the taxonomy in which the term resides. The default taxonomies arecategory,link_category, andpost_tag. -
term_taxonomy_idis a unique ID for the term+taxonomy pair.
The rest of the fields provide information about the term in the context of the taxonomy.
- The
parentfield keeps track of hierarchical relationships between terms in the taxonomy. -
descriptionprovides a taxonomy specific description of the term. -
counttracks how many objects are associated with the term+taxonomy pair. Given a taxonomy ofcategory,counttracks how many posts are in the category.
wp_term_relationships
The final table, term_relationships, relates objects such as posts or links to a term_taxonomy_id from the term_taxonomy table.
object_id bigint(20) NOT NULL default 0, term_taxonomy_id bigint(20) NOT NULL default 0, PRIMARY KEY (object_id,term_taxonomy_id), KEY term_taxonomy_id (term_taxonomy_id)
-
object_idis the ID of a post or link. -
term_taxonomy_idis an ID from the term_taxonomy table designating a particular term+taxonomy pair.
