wordpress - Understanding Taxonomies -


as understand term, "taxonomy" way group posts, "products." can indicate post "product" specifying "product" taxonomy of post in wp_insert_post(). add custom field post, "group=product" , pull product posts, ask records had custom field of group=product. i'm assuming, though, latter method require wordpress through posts had custom field of group value product, while taxonomy method threads records have taxonomy "product" they're accessed directly instead of through search through every post. correct?

second, "category" built in taxonomy? if assign category of "product" when wp_insert_post() when ask records category =product, wordpress able access product posts directly, i.e., posts category=product?

i think can understand studying following related tables:

  • wp_terms
  • wp_term_taxonomy
  • wp_term_relationships

wp_terms:

it's notable columns term_id, name, , slug.

as word implies, term name of something. example league of football teams, term name of specific team in league. let's use foo team name.

and may know - each name have slug , id in order easy common programming tasks relate managing terms.

wp_term_taxonomy:

let's @ name of table, can guess table relates terms taxonomies. table's major columns term_taxonomy_id, term_id, taxonomy, , taxonomy_description.

this table grouping collection of terms , give them taxonomy (i.e categorizes them). since foo term , term football team, it's appropriate categorize such football-team.

bar different team name (another term). can group/categorize both foo , bar football teams, such both have taxonomy/category football-teams. , of course, there's description each taxonomy explain category is.

note each relationship created have unique id term_taxonomy_id, relationship foo , football-team have unique id. bar , football-team. important put consideration when view next table.

wp_term_relationships:

major columns object_id , term_taxonomy_id. relationship between each object_id (a post id example) , id of relationship between term , taxonomy/category.

so post have term_taxonomy_id tell term representing post (could post team foo) , of category term (football-team).

when consider explanation above , take @ codex wp_insert_post(), part:

post_category: equivalent calling wp_set_post_categories().

tags_input: equivalent calling wp_set_post_tags().

tax_input: equivalent calling wp_set_post_terms() each custom taxonomy in array. if current user doesn't have capability work taxonomy, must use wp_set_object_terms() instead.

you able understand how wordpress taxonomies work , answer own questions.


Comments