WordPress by default will create some core tables in the database during installation. These tables are sufficient for WordPress to work properly. However, plugins will add additional tables to enhance the functions. For example, WooCommerce plugin will add more than 25 tables in the database. Unfortunately, most plugins including WooCommerce will not delete the database tables when deleting the plugin. This may create confusion when you look into the database about the core table and tables created by plugins. Here is the details of WordPress database structure explaining the function of each core table.
WordPress Database Structure
WordPress database will have the following 12 tables as part of default installation:
|Table||Purpose||Admin Panel Section|
|wp_posts||Stores content||Posts / Pages > Add New|
|wp_postmeta||Stores post meta data||Posts / Pages > Add New|
|wp_comments||Keep comments from users||Comments|
|wp_commentmeta||Keep comment meta data||Comments|
|wp_terms||Stores categories and tags||Posts > Categories|
Posts > Tags
|wp_termmeta||Meta data for categories and tags||Posts > Categories|
Posts > Tags
|wp_term_relationships||Term relationship with posts||Posts > Categories|
Posts > Tags
|wp_term_taxonomy||Additional details for terms table|
|wp_users||User details||Users > Add New|
|wp_usermeta||User meta data||Users > Add New|
|wp_links||Link details||Not used|
|wp_options||Site settings||Settings section|
The above list of tables are for single site installation and for multi-site you will have additional tables like wp_blogs, wp_blogmeta, wp_sites, wp_sitemeta, wp_blog_versions, wp_registration_log and wp_signups. In this article, we will focus only on the single site installation.
Any other tables in your database is created by plugins. Remember, WordPress uses “wp_” for table prefix by default. However, you may find different prefix based on the one you used during installation. Softaculous and other on-click WordPress installers will create different prefix automatically when installing WordPress through your hosting account. As you can see, the below example on our demo installation has “wpeg_” as table prefix.
Core WordPress team has a beautiful picture to explain the structure of WordPress database. It clearly explains the structure and fields used by each table.
WordPress Tables Explained
Let us start with explaining the tables based on the frontend look of a WordPress page. Below is a sample page of this site that has text, image, link and comment. The corresponding table is mentioned from where you can find the data in the backend.
In addition, you can find each table data under corresponding sections of WordPress admin panel as mentioned in the above table.
Posts Table: wp_posts
Many people misunderstand the meaning of posts table that it only stores posts. WordPress stores all your text content in wp_posts table regardless of post types. It means, you can find all your content in wp_posts tables for posts, pages and any other custom post types. In addition, you can also find attachments, revisions and autosave in the same table.
Post Meta: wp_postmeta
The best example of explaining post meta is with Yoast SEO plugin. When using the plugin, you can see the meta box for adding SEO title, meta description, etc. for each post. WordPress will store all these post associated data in wp_postmeta table.
This is one of the fast growing in many WordPress installation due to improper use of plugins. Check out our article on how to cleanup postmeta table in WordPress.
If you have enabled comments in WordPress, you will see an option to leave the comment under each post or page. WordPress will store all user comments under “wp_comments” table.
Comments table is also one of the fast growing in many WordPress installation due to spam comments. You should use Akismet, captcha or any other way of moderating comments to avoid the table contains junk comments.
Comments Meta: wp_commentmeta
Similar to post meta, WordPress will store all comments meta in wp_commentmeta table.
Terms table stores categories and tags for the posts.
Term Meta: wp_termmeta
All term meta data is stored in wp_termmeta table.
It extends the details of the terms stored in wp_terms table.
This table stores the category and tags relationship to posts.
You can find all registered users on your site in this table. Remember, this table will not have the commenters who leave comments without registration. You have to find that details in wp_commentmeta table.
User Meta: wp_usermeta
Meta data related to users are stored in wp_usermeta table.
Earlier WordPress had an option to create links like creating new posts. However, this was removed subsequently and the table is no more used. You should see this table empty unless theme or plugin developer using it.
Options table stores all site wide settings like site URL, active plugins, admin username, etc. Plugins and theme developer often use options table to load the settings. If options table create problem for you, check out our article on how to cleanup wp_options table.
Where can i find a layout of the wp_posts table for the other post types. Everything only shows blog posts.