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

Original author: Rachel McCollin
  • Transfer
  • Tutorial

This article is a translation of the first Rachel McCollin article from the data cycle in WordPress. It shelves the data structure, content types and their relationship in WordPress. It will be useful primarily for beginners, but professionals can find something new for themselves.

Remark from the translator
The translation uses terminology according to the WordPress codex.
  • Post - post
  • Page - page,
  • Attachment - an 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, it is not the translation “content” that is used, but “content”. I believe this translation is more correct in the text.
In some cases, the transcript in English is given in parentheses for a clear understanding.

Comments on errors and typos, please inform in PM.

A WordPress site consists of three main elements:

  • WordPress installation itself
  • The contents of the wp-content directory, which includes themes, plugins, and downloads
  • A database where content is stored as data.

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

This series of articles will take a closer look at aspects of the WordPress database. This series consists of nine parts:

  1. Introduction (now you read it)
  2. Relationships Between Data
  3. Content Types
  4. User data
  5. Metadata
  6. Taxonomy, Categories, Tags, and Terms
  7. Taxonomy VS Metadata
  8. Option table
  9. WordPress Multisite Data

This article discusses 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.

WordPress Content Types

Before parsing the data stored in the WordPress database, consider the types of content. The following standard types of content exist:

  • Posts
  • Pages
  • Custom post types
  • Attachments
  • Links
  • Menu items (navigation menu items)

These types of content have the following data:

  • Categories
  • Tags
  • Custom taxonomies and terms
  • Metadata (post metadata)

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

  • Widgets
  • Options
  • Users
  • Sites for MU WordPress
  • Non-standard content (hardcoded content), which some themes / plugins add.
  • Third party content (e.g. RSS)

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

WordPress Database Structure

WordPress uses several related tables. Between them one-to-many relationships are established. For example, there can be many comments on one page. The diagram below is taken from WordPress code . It shows 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 record (example post_id). In more detail for each table:

TableDataLinks to other tables
Entries, pages, attachments, editions, user entries
wp_postmeta via post_id
wp_term_relationships via post_id
Metadata for posts, pages, etc. wp_posts via post_id
Comments wp_posts via post_id
Comment metadata wp_comments via comment_id
Links between taxonomies and posts, pages, etc.wp_posts via post_id
wp_term_taxonomy through term_taxonomy_id
Taxonomies (including categories and tags) wp_term_relationships via term_taxonomy_id
Your categories, labels and terms of custom taxonomies
wp_term_taxonomy via term_id
Links in your block (usually not used now) wp_term_relationships via link_id
Users wp_posts via post_author
Metadata for each user wp_users via user_id
Options and site settings
(set in the admin panel on the settings page and in themes / plugins)
Not available

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. This is where most of the data is stored.
  • Only one table is unrelated to others - the wp_options table. It stores information 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 WordPress settings, you can specify that only registered users can leave a comment. Despite this, WordPress does not keep a link about the comments and the user who posted them.
  • WordPress MU have some extra table. 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 list below shows which database tables are used to store what type of content.

Content typeTable
Posts wp_posts
Pages wp_posts
Custom post types wp_posts
Attachments wp_posts
Links wp_links
Menu items (navigation menu items) wp_posts
Categories wp_terms
Tags wp_terms
Custom taxonomies wp_term_taxonomy
Custom taxonomy 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 entries)
wp_options (if added to widgets) Theme
/ plugin files
Third party contentwp_posts (if added to entries)
wp_options (if added to widgets) Theme
/ plugin files

It is easy to see 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 considered in subsequent articles.


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

Only registered users can participate in the survey. Please come in.

Should I translate subsequent articles

  • 81.3% Yes 341
  • 10.7% No (not interested or read in English) 45
  • 7.8% I don't care 33

Also popular now: