The WordPress Database Structure

Estimated reading time: 5 minutes
Category: WordPress

Having worked with WordPress over time, you likely have encountered the database structure. It’s important to understand how WordPress database tables are organized, as this shows where the CMS stores all the content, user data, and configurations. In this post, we will look at all the default WordPress database tables and what each stores.

By default, WordPress uses a single database with 12 core tables, though additional tables can be added by plugins or custom development.

List of WordPress Core Tables:

Here’s a look at each of these core tables:

wp_options

The wp_options table stores information about your website’s settings. Each row in the wp_options table represents a specific setting. For example, the siteurl option stores the URL of your website, and the blogdescription option stores the tagline of your website. The wp_options table also stores information about your website’s active theme and active plugins.

Data is stored in the wp_options table using a key-value format. The key is the name of the option, and the value is the value of the option.

It is also possible to store serialized data in the wp_options table. Serialized data is a string that contains multiple values. Serialized data is often used to store arrays and objects of data. A good example of this is the list of active plugins, which is stored as a serialized array.

  • option_name and option_value: Key-value pairs that store settings like site URL, home URL, active plugins, and more.

wp_posts

The wp_posts table is probably the most important table in a WordPress site, and stores information about your website’s posts, pages, or any other custom post type. Each row in the wp_posts table represents a single post.

  • ID: Unique identifier for each content item.
  • post_title: The title of the post or page.
  • post_content: The main content.
  • post_type: Defines the content type, such as post, page, attachment, or custom post types.
  • post_status: Defines the status (published, draft, etc.).

wp_postmeta

The wp_postmeta table stores additional information about each post, known as metadata. For example, featured images, custom fields, and plugin-related data are often stored here.

  • post_id: Links the metadata to a specific post in wp_posts
  • meta_key and meta_value: Custom fields and values for each post

wp_users

This table contains information about registered users. WordPress supports various user roles, such as Administrator, Editor, and Subscriber, each with specific permissions.

  • ID: Unique identifier for each user.
  • user_login: The username for logging in.
  • user_pass: Stores the user’s hashed password.
  • user_email: User’s email address.

wp_usermeta

Like other meta tables wp_usermeta stores metadata for each user, including custom fields and roles assigned to users.

  • user_id: Links metadata to a specific user in wp_users.
  • meta_key and meta_value: Custom data about each user.

wp_comments

The wp_comments table stores information about the comments on your posts and pages. Whenever someone comments on a post or page, this table is where that comment is stored. Each row in the wp_comments table represents a single comment.

  • comment_ID: Unique identifier for each comment.
  • comment_post_ID: Links comment to a specific post in wp_posts.
  • comment_author and comment_content: Stores the author name and comment text.

wp_commentmeta

The wp_commentmeta table stores metadata about each comment, often used by plugins for additional data.

  • comment_id: Links metadata to a specific comment in wp_comments.
  • meta_key and meta_value: Custom fields for each comment.

wp_terms

This table manages terms (tags, categories, or any custom taxonomy). It contains basic term information term_id, name and slug.

  • term_id: Unique identifier for each term.
  • name: The display name of the term.
  • slug: URL-friendly version of the term.

wp_termmeta

The wp_termmeta allows us to store additional information similar to the post meta and the comments meta table.

  • meta_id: Unique identifier for each metadata entry.
  • term_id: Links the metadata to a specific term in the wp_terms table.
  • meta_key and meta_value: Store custom metadata keys and their corresponding values.

wp_term_taxonomy

The wp_term_taxonomy table describes the type of taxonomy each term belongs to, such as category, tag, or custom taxonomy.

  • term_taxonomy_id: Unique identifier for each taxonomy.
  • term_id: Links to wp_terms.
  • taxonomy: Specifies taxonomy type.

wp_term_relationships

This table links posts (and custom post types) to terms, defining relationships between content and taxonomies.

  • object_id: Refers to the ID in wp_posts.
  • term_taxonomy_id: Connects the term taxonomy to a specific object (like a post).

wp_links (Deprecated)

Originally used to manage blogroll links, this table has largely fallen out of use. It still appears in some WordPress installations for backward compatibility.

Plugins often add their own tables to the database for storing plugin-specific data. WooCommerce, for example, adds tables for products, orders, and order items. When working with a customized WordPress site, it’s common to encounter these tables.

Leave a Reply

Your email address will not be published. Required fields are marked *