2023-06-11 / 286阅
WordPress是一款开源的内容管理系统,其数据库结构采用关系型数据库设计,基于MySQL实现。本文介绍了WordPress数据库结构的各个方面。
WordPress默认情况下会在MySQL数据库中创建11张表,分别是:
图示:
+-----------------------+
| wp_commentmeta |
+-----------------------+
| meta_id |
| comment_id |
| meta_key |
| meta_value |
+-----------------------+
+-----------+
| wp_comments |
+-----------+
| comment_ID|
| comment_post_ID|
| comment_author|
| comment_author_email|
| comment_author_url|
| comment_author_IP|
| comment_date|
| comment_content|
etc..
+-----------+
+---------------------+
| wp_links |
+---------------------+
| link_id |
| link_url |
| link_name |
| link_image |
| link_target |
| link_description |
| link_visible |
| link_owner |
| link_rating |
| link_updated |
| link_rel |
| link_notes |
| link_rss |
+---------------------+
+--------------------+
| wp_options |
+--------------------+
| option_id |
| option_name |
| option_value |
| autoload |
+--------------------+
+------------------------+
| wp_postmeta |
+------------------------+
| meta_id |
| post_id |
| meta_key |
| meta_value |
+------------------------+
+-------------------------+
| wp_posts |
+-------------------------+
| ID |
| post_author |
| post_date |
| post_date_gmt |
| post_content |
| post_title |
| post_excerpt |
| post_status |
| comment_status |
| ping_status |
| post_password |
| post_name |
| to_ping |
| pinged |
| post_modified |
| post_modified_gmt |
| post_content_filtered |
| post_parent |
| guid |
| menu_order |
| post_type |
| post_mime_type |
| comment_count |
+-------------------------+
+------------------------+
| wp_terms |
+------------------------+
| term_id |
| name |
| slug |
| term_group |
+------------------------+
+--------------------------------+
| wp_term_relationships |
+--------------------------------+
| object_id |
| term_taxonomy_id |
| term_order |
+--------------------------------+
+---------------------------------+
| wp_term_taxonomy |
+---------------------------------+
| term_taxonomy_id |
| term_id |
| taxonomy |
| description |
| parent |
| count |
+---------------------------------+
+------------------------+
| wp_usermeta |
+------------------------+
| meta_id |
| user_id |
| meta_key |
| meta_value |
+------------------------+
+-------------------------+
| wp_users |
+-------------------------+
| ID |
| user_login |
| user_pass |
| user_nicename |
| user_email |
| user_url |
| user_registered |
| user_activation_key |
| user_status |
| display_name |
+-------------------------+
wp_posts表和wp_postmeta表通过ID关联,wp_postmeta表中是文章相关的meta信息,包括各种自定义字段等等。ID和meta表中的post_id关联。
wp_terms表存放文章分类和标签的名称和缩略名(slug),wp_term_taxonomy是分类与标签的Taxonomy表,它分辨3种分类类型:category(文章分类)、post_tag(文章标签)与nav_menu。
wp_term_relationships表记录文章与分类/标签的关联关系,post_id与term_taxonomy_id建立索引关系。值得一提的是,默认情况下该表中只存储分类ID,如果需要获取分类/标签详细信息还需要额外查询wp_terms表。
wp_comments表记录所有的评论信息,wp_commentmeta是评论相关的meta信息,可自定义细分评论的属性。
wp_usermeta表中是用户相关的meta信息,包括各种自定义用户字段等等,ID和meta表中的user_id关联。
//获取某篇文章的标题
global $wpdb;
$post_id = 123; //具体文章ID
$query_result = $wpdb->get_results("SELECT post_title FROM $wpdb->posts WHERE ID = $post_id");
$post_title = $query_result[0]->post_title;
//获取某个用户的昵称
$display_name = get_user_meta($user_id, 'display_name', true);
阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228