📜 ⬆️ ⬇️

Understanding and working with data in WordPress. Part 1. Introduction


This article is a translation of the first article of Rachel McCollin from the data loop in WordPress. In it, the data structure, content types and their interrelation in WordPress are laid out on the shelves. It will be useful primarily for beginners, but professionals can also find something new for themselves.


Note from the translator
The translation uses terminology according to the WordPress code.
  • Post - record
  • Page - page,
  • Attachment - attachment
  • Revision - edition,
  • Comment - comment,
  • Taxonomy - taxonomy,
  • Category - category
  • Tag - tag
  • Term - term (specific meaning of user taxonomy)
  • User - user
  • Metadata - Metadata

The only exception is the term content. In most cases, the translation is not “content” but “content”. I think this translation is more correct in the text.
In some cases, in parentheses is the decoding in English for an unambiguous understanding.

Comments on errors and typos please report in a personal.


A WordPress site consists of three main elements:
')

Most WordPress users never work with a database directly. They may not even be aware that it is constantly working to ensure the operation of their website. When WordPress displays any page, it connects to the database to show the content that the authors have added to the site.

This series of articles will cover aspects of the WordPress database in detail. This series consists of nine parts:

  1. Introduction (you are reading it now)
  2. Data Relationships
  3. Types of content
  4. User Data
  5. Metadata
  6. Taxonomies, categories, tags and terms
  7. Taxonomies VS Metadata
  8. Option table
  9. WordPress Multisite Data

This article discusses the database tables and how they relate to content types. These types of content are used to work in WordPress and determine what, how and where should be stored.

Content Types in WordPress


Before parsing the data stored in the WordPress database, consider the types of content. There are such standard types of content:


These types of content have the following data:


In addition, there are content types stored in a different form:


All these types of content are stored in database tables or theme / plugin settings files. Each type can be represented as a separate entry in the table, and its part. In addition, they can be associated with data in other tables. For example, post data is associated with user data, so WordPress knows who the author is, which post.

WordPress database structure


WordPress uses several interrelated tables. One to many connections are established between them. For example, there may be a lot of comments on one page. The diagram below is taken from WordPress Codex . It shows the tables and the relationships between them:



Most tables are linked to one or more others using a single field. This field will be a unique identifier for each entry (post_id example). More details for each table:

TableDataLinks to other tables
wp_posts
Records, pages, attachments, editors, user records
wp_postmeta via post_id
wp_term_relationships via post_id
wp_postmeta
Metadata records, pages, etc.wp_posts via post_id
wp_comments
Commentswp_posts via post_id
wp_commentmeta
Comment Metadatawp_comments via comment_id
wp_term_relationships
Links between taxonomies and records, pages, etc.wp_posts via post_id
wp_term_taxonomy via term_taxonomy_id
wp_term_taxonomy
Taxonomies (including categories and tags)wp_term_relationships via term_taxonomy_id
wp_terms
Your categories, tags and terms for custom taxonomies
wp_term_taxonomy via term_id
wp_links
Links in your block (as a rule, not used now)wp_term_relationships via link_id
wp_users
Userswp_posts via post_author
wp_user_meta
Metadata for each userwp_users via user_id
wp_options
Site options and settings
(set in admin panel on settings page and in themes / plugins)
Will be out

It is worth noting a few things:


Link content and database tables



After reviewing the types of content in WordPress and the database tables used to store them, you can draw a correspondence between them. The following list shows which database tables are used to store which type of content.

Content typeTable
Postswp_posts
Pageswp_posts
Custom post types (custom post types)wp_posts
Attachments (attachments)wp_posts
Linkswp_links
Menu items (navigation menu items)wp_posts
Categorieswp_terms
Tagswp_terms
Custom taxonomies (custom taxonomies)wp_term_taxonomy
Terms of custom taxonomies (custom terms)wp_terms
Metadata (post metadata)wp_post_meta
Widgetswp_options
Optionswp_options
Userswp_users
Non-standard content (hardcoded content)wp_posts (if added to posts)
wp_options (if added to widgets)
Theme / plugin files
Third party contentwp_posts (if added to posts)
wp_options (if added to widgets)
Theme / plugin files


It is easy to notice that not all tables are used in the list. This is because some of them are used to store metadata. Others are used to store links. Both options will be discussed in subsequent articles.

Conclusion



I hope that now you better understand how and where WordPress stores various types of data, how it uses the database. The elements of this process will be discussed in more detail in subsequent articles. So the next article will look at the relationships between data. As well, we will dwell in more detail on how specific tables are related and how some of them are used exclusively for storing relationship data.

Source: https://habr.com/ru/post/233479/


All Articles