Let's take a look at 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 options that power your site.
As you learned in the web servers lesson, WordPress uses MySQL.
MySQL is a free open source database management system that is used by many popular web applications.
There are a few ways to interact directly with your WordPress database.
The majority of local development environments and hosting companies use a free tool called phpMyAdmin.
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.
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 install a plugin called 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 decide to use SQL Buddy, please remember to deactivate and delete the plugin when you're done using it.
Leaving it installed on your website is a possible security risk.
For the purposes of this lesson, we'll be using phpMyAdmin to inspect the database tables.
The WordPress database is made up of a number of 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 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.
The post 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-up.
Each row in the post table represents a single post.
The post meta table allows you to store additional information about each post.
The post meta also often referred to as custom fields.
The comments table stores information about the comments on your posts or pages.
Whenever someone comments on a post or page, this table is where the comment is stored.
Each row in the comments table represents a single comment.
Like the post meta table, the comment meta table can store additional information about each comment.
The users table stores all information about your website's users.
Again, each row in the users table represents a single user.
And like other meta tables, the user meta table can store additional information about each user.
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 a WordPress database all follow a similar pattern.
There is an insert, update and 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 some of 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.
And finally, wp_delete_post is the function to delete a post.
Then there are usually functions to either fetch all of 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 is the function to update a meta field.
And _delete_post_meta is the function to delete a meta field.
The terms, term_meta, term_relationships, and term_tuxonomy_tables are the tables that manage the categories and tags in your WordPress site.
The terms table stores information about your website's terms.
Each row in the 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 term taxonomy table.
The term relationships table stores the relationships between the terms and the appearance objects,
be that a post, page, or custom post type.
Finally, like other meta tables, the term meta table can store additional information about each term.
Similar to the functions that 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, either for term,
or taxonomy.
The WP options table stores information about your website's settings.
Each row in the options table represents a specific setting.
For example, the site URL option stores the URL of your website, and the blog description option stores the tagline of your website.
The options table also stores information about your website's active themes and plugins.
Data is stored in the 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 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 in a serialized array.
The options API is typically used, along with the settings API, to create setting pages for the WordPress admin, either via call, plugins or themes.
The options API provides functions to interact with the options table, like add option, update option and delete option.
The links table stores information about a website's links.
Links was the feature that was removed in WordPress version 3.5.
However, because you can still enable this functionality, the links table is included for backwards compatibility.
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 it.