How To Find Out WordPress Category Table in MYSQL?

See the Codex’s WordPress Taxonomy documentation.

WordPress 2.3 replaced the previous categories, post2cat, and link2cat tables with three a more flexible set of taxonomy tables.

wp_terms
wp_term_relationships
wp_term_taxonomy

wp_terms– holds the basic information about single terms.

term_id bigint(20) unsigned NOT NULL auto_increment,
name varchar(200) 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),
KEY name (name)
  • term_id is a unique ID for the term.
  • name is simply the name of the term.
  • slug is unique and is the name reduced to a URL friendly form.
  • term_group is a means of grouping together similar terms.

wp_term_taxonomy – defines the taxonomy – either tag, category, or custom taxonomy

term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
term_id bigint(20) unsigned NOT NULL default 0,
taxonomy varchar(32) NOT NULL default '',
description longtext NOT NULL,
parent bigint(20) unsigned NOT NULL default 0,
count bigint(20) NOT NULL default 0,
PRIMARY KEY  (term_taxonomy_id),
UNIQUE KEY term_id_taxonomy (term_id,taxonomy),
KEY taxonomy (taxonomy)
  • term_id is the ID of a term in the terms table.
  • taxonomy designates the taxonomy in which the term resides. The default taxonomies are category, link_category, and post_tag.
  • term_taxonomy_id is a unique ID for the term+taxonomy pair.
  • The parent field keeps track of hierarchical relationships between terms in the taxonomy.
  • description provides a taxonomy specific description of the term.
  • count tracks how many objects are associated with the term+taxonomy pair. For example, given a term of the category taxonomy, count tracks how many posts are in that specific category.

wp_term_relationships – contains the many-to-many relationship between WordPress objects such as posts or links to a term_taxonomy_id from the term_taxonomy table.

object_id bigint(20) unsigned NOT NULL default 0,
term_taxonomy_id bigint(20) unsigned NOT NULL default 0,
term_order int(11) NOT NULL default 0,
PRIMARY KEY  (object_id,term_taxonomy_id),
KEY term_taxonomy_id (term_taxonomy_id)
  • object_id is the ID of a post or link.
  • term_taxonomy_id is an ID from the term_taxonomy table designating a particular term+taxonomy pair.
  • term_order allows an ordering of terms for an object (see ticket #5857)

Leave a Comment