首页 问答 正文

WordPress的数据结构是什么样子的?

注册会员 / 悠然自学 / 2023-06-11/ 浏览 153 次

WordPress的数据结构是基于关系型数据库的,主要分为以下几个表:

  1. wp_users 表:用于存储用户信息,每个用户都有一个唯一的ID,这个ID会关联到其它表中。

  2. wp_posts 表:用于存储文章、页面和自定义文章类型的数据。每篇文章都有一个唯一的ID,这个ID也会关联到其它表中。

  3. wp_comments 表:用于存储评论数据,每条评论都有一个唯一的ID,评论的ID也会关联到其它表中。

  4. wp_terms 表:用于存储分类和标签的数据,每个分类或标签都有一个唯一的ID,这个ID会关联到其它表中。

  5. wp_term_taxonomy 表:用于存储分类和标签的关系数据,这个表让我们可以为不同的文章类型或自定义文章类型指定不同的分类或标签。

以下是一个简单的数据结构示例代码:

CREATE TABLE wp_users (
  ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  user_login VARCHAR(60) NOT NULL,
  user_pass VARCHAR(255) NOT NULL,
  user_email VARCHAR(100) NOT NULL,
  user_registered DATETIME NOT NULL,
  user_status INT(11) NOT NULL DEFAULT 0,
  display_name VARCHAR(250) NOT NULL,
  PRIMARY KEY (ID),
  KEY user_login_key (user_login),
  KEY user_email_key (user_email)
);

CREATE TABLE wp_posts (
  ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  post_author BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  post_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  post_date_gmt DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  post_content LONGTEXT NOT NULL,
  post_title TEXT NOT NULL,
  post_excerpt TEXT NOT NULL,
  post_status VARCHAR(20) NOT NULL DEFAULT 'publish',
  comment_status VARCHAR(20) NOT NULL DEFAULT 'open',
  ping_status VARCHAR(20) NOT NULL DEFAULT 'open',
  post_password VARCHAR(20) NOT NULL DEFAULT '',
  post_name VARCHAR(200) NOT NULL DEFAULT '',
  to_ping TEXT NOT NULL,
  pinged TEXT NOT NULL,
  post_modified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  post_modified_gmt DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  post_content_filtered LONGTEXT NOT NULL,
  post_parent BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  guid VARCHAR(255) NOT NULL DEFAULT '',
  menu_order INT(11) NOT NULL DEFAULT 0,
  post_type VARCHAR(20) NOT NULL DEFAULT 'post',
  post_mime_type VARCHAR(100) NOT NULL DEFAULT '',
  comment_count BIGINT(20) NOT NULL DEFAULT 0,
  PRIMARY KEY (ID),
  KEY post_name (post_name),
  KEY type_status_date (post_type, post_status, post_date, ID),
  KEY post_parent (post_parent),
  KEY post_author (post_author)
);

CREATE TABLE wp_comments (
  comment_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  comment_post_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  comment_author VARCHAR(255) NOT NULL DEFAULT '',
  comment_author_email VARCHAR(100) NOT NULL DEFAULT '',
  comment_author_url VARCHAR(200) NOT NULL DEFAULT '',
  comment_author_IP VARCHAR(100) NOT NULL DEFAULT '',
  comment_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  comment_date_gmt DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  comment_content TEXT NOT NULL,
  comment_approved TINYINT(1) NOT NULL DEFAULT 1,
  comment_agent VARCHAR(255) NOT NULL DEFAULT '',
  comment_type VARCHAR(20) NOT NULL DEFAULT '',
  comment_parent BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  user_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (comment_ID),
  KEY comment_post_ID (comment_post_ID),
  KEY comment_approved_date_gmt (comment_approved, comment_date_gmt),
  KEY comment_date_gmt (comment_date_gmt),
  KEY comment_parent (comment_parent),
  KEY comment_author_email (comment_author_email(10))
);

CREATE TABLE wp_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)
);

CREATE TABLE wp_term_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)
); 
大家谈论
    我的见解