Title: The WordPress database
Published: 1 February 2024
Last modified: 11 March 2025

---

[Home](https://learn.wordpress.org)[Courses](https://learn.wordpress.org/courses/)
[Beginner WordPress Developer](https://learn.wordpress.org/course/beginner-wordpress-developer/)
The WordPress database

 [ Exit Course ](https://learn.wordpress.org/course/beginner-wordpress-developer/)

 1.   a.  [   WordPress and web servers  ](https://learn.wordpress.org/lesson/wordpress-and-web-servers/)
         [Preview](https://learn.wordpress.org/lesson/wordpress-and-web-servers/)
      b.  [   The WordPress file structure  ](https://learn.wordpress.org/lesson/the-wordpress-file-structure/)
         [Preview](https://learn.wordpress.org/lesson/the-wordpress-file-structure/)
      c.  [   The WordPress database  ](https://learn.wordpress.org/lesson/the-wordpress-database/)
         [Preview](https://learn.wordpress.org/lesson/the-wordpress-database/)
      d.  [   Permalinks, rewriting urls on Apache and Nginx  ](https://learn.wordpress.org/lesson/permalinks-rewriting-urls-on-apache-and-nginx/)
         [Preview](https://learn.wordpress.org/lesson/permalinks-rewriting-urls-on-apache-and-nginx/)
      e.  [   Front-end page request  ](https://learn.wordpress.org/lesson/front-end-page-request/)
         [Preview](https://learn.wordpress.org/lesson/front-end-page-request/)
      f.  [   Admin page request  ](https://learn.wordpress.org/lesson/admin-page-request/)
         [Preview](https://learn.wordpress.org/lesson/admin-page-request/)
 2.   6 lessons
 3.   a.  [   Local development environment  ](https://learn.wordpress.org/lesson/local-development-environment/)
         [Preview](https://learn.wordpress.org/lesson/local-development-environment/)
      b.  [   WordPress Installation  ](https://learn.wordpress.org/lesson/wordpress-installation/)
         [Preview](https://learn.wordpress.org/lesson/wordpress-installation/)
      c.  [   Code editor  ](https://learn.wordpress.org/lesson/code-editor/) [Preview](https://learn.wordpress.org/lesson/code-editor/)
      d.  [   Other useful development tools  ](https://learn.wordpress.org/lesson/other-useful-development-tools/)
         [Preview](https://learn.wordpress.org/lesson/other-useful-development-tools/)
 4.   4 lessons
 5.   a.  [   HTML  ](https://learn.wordpress.org/lesson/html/) [Preview](https://learn.wordpress.org/lesson/html/)
      b.  [   CSS  ](https://learn.wordpress.org/lesson/css/) [Preview](https://learn.wordpress.org/lesson/css/)
      c.  [   JavaScript  ](https://learn.wordpress.org/lesson/javascript/) [Preview](https://learn.wordpress.org/lesson/javascript/)
      d.  [   PHP  ](https://learn.wordpress.org/lesson/php/) [Preview](https://learn.wordpress.org/lesson/php/)
      e.  [   MySQL  ](https://learn.wordpress.org/lesson/mysql/) [Preview](https://learn.wordpress.org/lesson/mysql/)
 6.   5 lessons
 7.   a.  [   WordPress Hooks  ](https://learn.wordpress.org/lesson/wordpress-hooks/) 
         [Preview](https://learn.wordpress.org/lesson/wordpress-hooks/)
      b.  [   Action Hooks  ](https://learn.wordpress.org/lesson/action-hooks/) [Preview](https://learn.wordpress.org/lesson/action-hooks/)
      c.  [   Filter Hooks  ](https://learn.wordpress.org/lesson/filter-hooks/) [Preview](https://learn.wordpress.org/lesson/filter-hooks/)
      d.  [   Working with hooks  ](https://learn.wordpress.org/lesson/working-with-hooks/)
         [Preview](https://learn.wordpress.org/lesson/working-with-hooks/)
 8.   4 lessons
 9.   a.  [   Introduction to themes for developers  ](https://learn.wordpress.org/lesson/what-is-a-theme/)
         [Preview](https://learn.wordpress.org/lesson/what-is-a-theme/)
      b.  [   Theme structure  ](https://learn.wordpress.org/lesson/theme-structure/) 
         [Preview](https://learn.wordpress.org/lesson/theme-structure/)
      c.  [   Main stylesheet  ](https://learn.wordpress.org/lesson/main-stylesheet/) 
         [Preview](https://learn.wordpress.org/lesson/main-stylesheet/)
      d.  [   Templates  ](https://learn.wordpress.org/lesson/templates-3/) [Preview](https://learn.wordpress.org/lesson/templates-3/)
      e.  [   Global settings and styles  ](https://learn.wordpress.org/lesson/global-settings-and-styles/)
         [Preview](https://learn.wordpress.org/lesson/global-settings-and-styles/)
      f.  [   Create Block Theme plugin  ](https://learn.wordpress.org/lesson/create-block-theme-plugin/)
         [Preview](https://learn.wordpress.org/lesson/create-block-theme-plugin/)
 10.  6 lessons
 11.  a.  [   What is a plugin?  ](https://learn.wordpress.org/lesson/what-is-a-plugin/)
         [Preview](https://learn.wordpress.org/lesson/what-is-a-plugin/)
      b.  [   Plugin requirements  ](https://learn.wordpress.org/lesson/plugin-requirements/)
         [Preview](https://learn.wordpress.org/lesson/plugin-requirements/)
      c.  [   Custom post types  ](https://learn.wordpress.org/lesson/custom-post-types/)
         [Preview](https://learn.wordpress.org/lesson/custom-post-types/)
      d.  [   Custom taxonomies  ](https://learn.wordpress.org/lesson/custom-taxonomies/)
         [Preview](https://learn.wordpress.org/lesson/custom-taxonomies/)
      e.  [   Custom post type data  ](https://learn.wordpress.org/lesson/custom-post-type-data/)
         [Preview](https://learn.wordpress.org/lesson/custom-post-type-data/)
      f.  [   Enqueuing CSS or JavaScript  ](https://learn.wordpress.org/lesson/enqueuing-css-or-javascript/)
         [Preview](https://learn.wordpress.org/lesson/enqueuing-css-or-javascript/)
 12.  6 lessons
 13.  a.  [   Setting up your block development environment  ](https://learn.wordpress.org/lesson/setting-up-your-block-development-environment/)
         [Preview](https://learn.wordpress.org/lesson/setting-up-your-block-development-environment/)
      b.  [   Scaffolding a new block  ](https://learn.wordpress.org/lesson/scaffolding-a-new-block/)
         [Preview](https://learn.wordpress.org/lesson/scaffolding-a-new-block/)
      c.  [   Building your first block  ](https://learn.wordpress.org/lesson/building-your-first-block/)
         [Preview](https://learn.wordpress.org/lesson/building-your-first-block/)
      d.  [   Block functionality  ](https://learn.wordpress.org/lesson/block-functionality/)
         [Preview](https://learn.wordpress.org/lesson/block-functionality/)
      e.  [   Block attributes  ](https://learn.wordpress.org/lesson/block-attributes-2/)
         [Preview](https://learn.wordpress.org/lesson/block-attributes-2/)
      f.  [   Block supports and styles  ](https://learn.wordpress.org/lesson/block-supports-and-styles/)
         [Preview](https://learn.wordpress.org/lesson/block-supports-and-styles/)
      g.  [   Static vs dynamic blocks  ](https://learn.wordpress.org/lesson/static-vs-dynamic-blocks/)
         [Preview](https://learn.wordpress.org/lesson/static-vs-dynamic-blocks/)
 14.  7 lessons
 15.  a.  [   The WordPress REST API  ](https://learn.wordpress.org/lesson/the-wordpress-rest-api/)
         [Preview](https://learn.wordpress.org/lesson/the-wordpress-rest-api/)
      b.  [   Using the WordPress REST API  ](https://learn.wordpress.org/lesson/using-the-wordpress-rest-api/)
         [Preview](https://learn.wordpress.org/lesson/using-the-wordpress-rest-api/)
      c.  [   Interacting with the WordPress REST API  ](https://learn.wordpress.org/lesson/interacting-with-the-wordpress-rest-api/)
         [Preview](https://learn.wordpress.org/lesson/interacting-with-the-wordpress-rest-api/)
      d.  [   Extending the WordPress REST API  ](https://learn.wordpress.org/lesson/extending-the-wordpress-rest-api/)
         [Preview](https://learn.wordpress.org/lesson/extending-the-wordpress-rest-api/)
 16.  4 lessons
 17.  a.  [   Securely developing plugins and themes  ](https://learn.wordpress.org/lesson/securely-developing-plugins-and-themes/)
         [Preview](https://learn.wordpress.org/lesson/securely-developing-plugins-and-themes/)
      b.  [   Fixing common security vulnerabilities  ](https://learn.wordpress.org/lesson/fixing-common-security-vulnerabilities/)
         [Preview](https://learn.wordpress.org/lesson/fixing-common-security-vulnerabilities/)
      c.  [   Tools to detect security vulnerabilities  ](https://learn.wordpress.org/lesson/tools-to-detect-security-vulnerabilities/)
         [Preview](https://learn.wordpress.org/lesson/tools-to-detect-security-vulnerabilities/)
 18.  3 lessons
 19.  a.  [   What is Internationalization?  ](https://learn.wordpress.org/lesson/what-is-internationalization/)
         [Preview](https://learn.wordpress.org/lesson/what-is-internationalization/)
      b.  [   The commonly used Internationalization functions  ](https://learn.wordpress.org/lesson/the-commonly-used-internationalization-functions/)
         [Preview](https://learn.wordpress.org/lesson/the-commonly-used-internationalization-functions/)
 20.  2 lessons
 21.  a.  [   Setting up a WordPress multisite network  ](https://learn.wordpress.org/lesson/setting-up-a-wordpress-multisite-network/)
         [Preview](https://learn.wordpress.org/lesson/setting-up-a-wordpress-multisite-network/)
      b.  [   Managing a WordPress multisite network  ](https://learn.wordpress.org/lesson/managing-a-wordpress-multisite-network/)
         [Preview](https://learn.wordpress.org/lesson/managing-a-wordpress-multisite-network/)
      c.  [   Advanced multisite management  ](https://learn.wordpress.org/lesson/advanced-multisite-management/)
         [Preview](https://learn.wordpress.org/lesson/advanced-multisite-management/)
      d.  [   Developing for a multisite network  ](https://learn.wordpress.org/lesson/developing-for-a-multisite-network/)
         [Preview](https://learn.wordpress.org/lesson/developing-for-a-multisite-network/)
      e.  [   Building plugins and themes that support multisite  ](https://learn.wordpress.org/lesson/building-plugins-and-themes-that-support-multisite/)
         [Preview](https://learn.wordpress.org/lesson/building-plugins-and-themes-that-support-multisite/)
 22.  5 lessons
 23.  a.  [   The built-in WordPress debugging options  ](https://learn.wordpress.org/lesson/the-built-in-wordpress-debugging-options/)
         [Preview](https://learn.wordpress.org/lesson/the-built-in-wordpress-debugging-options/)
      b.  [   Examining the state of your PHP code  ](https://learn.wordpress.org/lesson/examining-the-state-of-your-php-code/)
         [Preview](https://learn.wordpress.org/lesson/examining-the-state-of-your-php-code/)
      c.  [   Examining the state of your JavaScript code  ](https://learn.wordpress.org/lesson/examining-the-state-of-your-javascript-code/)
         [Preview](https://learn.wordpress.org/lesson/examining-the-state-of-your-javascript-code/)
      d.  [   Useful debugging plugins  ](https://learn.wordpress.org/lesson/useful-debugging-plugins/)
         [Preview](https://learn.wordpress.org/lesson/useful-debugging-plugins/)
 24.  4 lessons
 25.  a.  [   Quiz time  ](https://learn.wordpress.org/lesson/quiz-time/)
 26.  1 lesson, 1 quiz
 27.  a.  [   Time to test your skills  ](https://learn.wordpress.org/lesson/time-to-test-your-skills/)
 28.  1 lesson, 1 quiz
 29.  a.  [   Test your knowledge  ](https://learn.wordpress.org/lesson/test-your-knowledge/)
 30.  1 lesson, 1 quiz

### A brief overview of how WordPress works

# The WordPress database

WordPress uses a database to store, retrieve, and display all the content that you
create on your website. This includes posts, pages, comments, and more.

The database is also used to store information about your website’s users, and various
site options that power your site.

As you learned in the Web Servers lesson, WordPress uses [MySQL](https://www.mysql.com/).
MySQL is a free, open-source database management system that is used by many popular
web applications.

## Interacting with your WordPress database

There are a few ways to interact directly with your WordPress database.

The majority of local development environments or hosting companies use a free tool
called [phpMyAdmin](https://www.phpmyadmin.net/). phpMyAdmin is a web-based tool
that allows you to interact with your WordPress database using a web browser.

An alternative to phpMyAdmin is a tool called [Adminer](https://www.adminer.org/).
Adminer is a single PHP file that you can upload to your website, and it provides
a similar interface to phpMyAdmin. Some hosting companies and local development 
environments prefer to use Adminer instead of phpMyAdmin.

Finally, if you don’t have access to either, you can also install a plugin called
[SQL Buddy](https://wordpress.org/plugins/sql-buddy/).

This is a free WordPress plugin that provides a similar interface to phpMyAdmin 
and Adminer, but it runs inside your WordPress dashboard.

If you do decide to use SQL Buddy, please remember to deactivate and delete the 
plugin when you are done using it. Leaving it installed on your website is a possible
security risk.

## Database Tables

For the purposes of this lesson, we’ll be using PhpMyAdmin to inspect the database
tables.

The WordPress database is made up of many tables. Each table stores a different 
type of data for your website.

Each table has the same prefix, which is defined in the `wp-config.php` file. By
default, the prefix is `wp_`, but you can change this to anything you like during
the WordPress installation process.

Let’s start by looking at the most important tables for managing content.

### wp_posts and wp_postmeta

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. The `wp_postmeta` table
allows you to store additional information about each post. The post meta are also
often referred to as custom fields.

### wp_comments and wp_commentmeta

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. The `
wp_commentmeta` table can store additional information about each comment.

### wp_user and wp_usermeta

The `wp_users` table stores all the information about your website’s users. Each
row in the `wp_users` table represents a single user. Like other meta tables, the`
wp_usermeta` table can store additional information about each user.

## Functions to interact with posts, comments, and users

For all WordPress database tables, there are functions that you can use to interact
with that table.

These functions form part of the WordPress Database API.

All of these functions can be found by using the search feature in the WordPress
developer documentation, under Code Reference.

Generally, the functions that you can use to interact with the WordPress database
all follow a similar pattern.

There is an insert function, an update function, and a delete function.

These usually have the same name, with the prefix `wp_` followed by the action, 
followed by the name of the table.

Let’s look at these functions for posts for example:

 * `wp_insert_post` is the function to create a new post
 * `wp_update_post` is the function to update an existing post
 * `wp_delete_post` is the function to delete a post

Then there are usually functions to fetch either all the records from a table, or
a single record.

These usually have the same name, with the prefix `get_` followed by either the 
singular or plural name of the table.

So for example `get_posts` is the function to fetch a collection of posts.

And `get_post` is the function to fetch a singular post.

Each of these functions typically has a number of parameters that you can use to
filter the results that are returned.

Then, there are also functions to interact with any meta tables, usually to insert,
update, or delete meta fields.

These usually have the same name, with the action, followed by the singular name
of the table, followed by `_meta`.

So for example for posts, `add_post_meta` is the function to insert a meta field.

Similarly `update_post_meta` the function to update a meta field and `delete_post_meta`
the function to delete a meta field.

## wp_terms, wp_termmeta, wp_term_relationships, and wp_term_taxonomy

The `wp_terms`, `wp_termmeta`, `wp_term_relationships`, and `wp_term_taxonomy` tables
are the tables that manage the categories and tags in your WordPress site.

The `wp_terms` table stores information about your website’s terms. Each row in 
the `wp_terms` table represents a single term. Under the hood, categories and tags
are both terms.

What determines whether they are a category or a tag is the taxonomy that they are
associated with, which is stored in the `wp_term_taxonomy` table.

The `wp_term_relationships` table stores the relationships between terms and their
parent objects, be that a post, page, or custom post type.

Finally, The `wp_termmeta` table can store additional information about each term.

### Functions to interact with terms and taxonomies

Similar to the functions to interact with posts, comments, and users, there are 
also functions to interact with terms and taxonomies, which can be found by searching
the WordPress Code Reference for term or taxonomy.

### 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.

### Functions to interact with options

The [Options API](https://developer.wordpress.org/apis/options/) is typically used
along with the [Settings API](https://developer.wordpress.org/apis/settings/) to
create settings pages for the WordPress dashboard, either via core, plugins, and
themes. The Options API provides functions to interact with the `wp_options` table,
like `add_option`, `update_option`, and `delete_option`.

### wp_links

The `wp_links` table stores information about your website’s links. Links was a 
feature that was [removed from WordPress in version 3.5](https://core.trac.wordpress.org/ticket/21307).

However, because it is still possible to re-enable this functionality using [the Links Manager plugin](https://wordpress.org/plugins/link-manager/),
the table has remained for backwards compatibility.

## Conclusion

Being able to correctly identify and interact with the tables in a WordPress database
is an extremely useful skill, and will help you to better understand how WordPress
works when you are developing with WordPress.

 This is a preview lesson

Register or sign in to take this lesson.

 [ Take course ](https://learn.wordpress.org/course/beginner-wordpress-developer/)

 [ Sign in ](https://login.wordpress.org/?redirect_to=https%3A%2F%2Flearn.wordpress.org%2Flesson%2Fthe-wordpress-database%2F&locale=en_US)

##  Suggestions

 Found a typo, grammar error or outdated screenshot? [Contact us](https://learn.wordpress.org/report-content-feedback/).