
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 translatorThe 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:
')
- WordPress installation itself
- The contents of the wp-content directory, which includes themes, plugins and downloads
- Database where content is stored as data.
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:
- Introduction (you are reading it now)
- Data Relationships
- Types of content
- User Data
- Metadata
- Taxonomies, categories, tags and terms
- Taxonomies VS Metadata
- Option table
- 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:
- Posts
- Pages
- Custom post types (custom post types)
- Attachments (attachments)
- Links
- Menu items (navigation menu items)
These types of content have the following data:
- Categories
- Tags
- Custom taxonomies (custom taxonomies and terms)
- Metadata (post metadata)
In addition, there are content types stored in a different form:
- Widgets
- Options
- Users
- Sites for MU WordPress
- Non-standard content (hardcoded content), which add some themes / plugins.
- Third party content (e.g. RSS)
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:
Table | Data | Links 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
| Comments | wp_posts via post_id
|
wp_commentmeta
| Comment Metadata | wp_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
| Users | wp_posts via post_author
|
wp_user_meta
| Metadata for each user | wp_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:
- Database tables are prefixed with wp_ by default. You can change it (for example, during installation).
- The wp_posts table is the most important. That is where most of the data is stored.
- Only one table is not related to the others - the wp_options table. It stores data about the site and WordPress settings that are not related to posts or users.
- Two tables are used to store taxonomy data. This will be a separate article.
- In the wp_users and wp_comments tables, the data is not related. In the settings of WordPress, you can specify that only registered users can leave a comment. Despite this, WordPress does not store links about the comments and the user who sent them.
- WordPress MU have some extra spreadsheet. Their consideration is beyond the scope of this article.
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 type | Table |
---|
Posts | wp_posts
|
Pages | wp_posts
|
Custom post types (custom post types) | wp_posts
|
Attachments (attachments) | wp_posts
|
Links | wp_links
|
Menu items (navigation menu items) | wp_posts
|
Categories | wp_terms
|
Tags | wp_terms
|
Custom taxonomies (custom taxonomies) | wp_term_taxonomy
|
Terms of custom taxonomies (custom terms) | wp_terms
|
Metadata (post metadata) | wp_post_meta
|
Widgets | wp_options
|
Options | wp_options
|
Users | wp_users
|
Non-standard content (hardcoded content) | wp_posts (if added to posts) wp_options (if added to widgets) Theme / plugin files |
Third party content | wp_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.