WordPress Database Structure and Tables

Senior WebCoder
WordPress is a dynamic content management system (CMS), meaning all the content, settings, and configurations of a WordPress site are stored in a MySQL (or MariaDB) database. The PHP-based WordPress core interacts with this database to retrieve, display, and update information whenever a visitor loads the website.
What the Database Stores
The database holds almost everything about your site, including:
- Content: Posts, pages, custom post types, revisions, drafts
- Users: Usernames, passwords (hashed), roles, permissions
- Settings: Site URL, theme options, plugin configurations
- Media: File references (images, videos, docs โ though the files themselves are stored on the server, their paths and metadata are stored in the DB)
- Comments: Comment text, author info, approval status
- Taxonomies: Categories, tags, and custom taxonomies
- Links & Metadata: Post meta, user meta, term meta
The Default WordPress Database Tables
By default, a fresh WordPress installation creates 12 core tables. Each table has a specific purpose:
1. wp_posts
This is the core table of WordPress. It stores posts, pages, custom post types, attachments, and revisions. Almost all site content lives here.
Columns:
ID
โ Unique identifier for each post (Primary Key)post_author
โ ID of the user who created the post (reference towp_users.ID
)post_date
โ Date and time when the post was createdpost_date_gmt
โ Same as above, in GMTpost_content
โ Main content of the post/pagepost_title
โ Title of the postpost_excerpt
โ Short summary or excerptpost_status
โ Status (e.g., publish, draft, trash)comment_status
โ Whether comments are allowed (open/closed)ping_status
โ Whether pingbacks/trackbacks are allowedpost_password
โ Password for password-protected postspost_name
โ URL-friendly slugto_ping
โ Sites to pingpinged
โ Sites that have been pingedpost_modified
โ Last modified date/timepost_modified_gmt
โ Last modified date/time in GMTpost_content_filtered
โ Used internally for filtered contentpost_parent
โ ID of parent post (for page hierarchy, attachments)guid
โ Unique reference link (often used for media attachments)menu_order
โ Order of pages in menuspost_type
โ Type (post, page, attachment, nav_menu_item, custom)post_mime_type
โ MIME type (for attachments, e.g., image/jpeg)comment_count
โ Number of comments related to the post
2. wp_postmeta
Stores extra information (metadata) about posts, often used by themes and plugins.
Columns:
meta_id
โ Unique identifier for each rowpost_id
โ Related post ID (wp_posts.ID
)meta_key
โ The key (e.g.,_thumbnail_id
,_yoast_wpseo_title
)meta_value
โ The value for the key
3. wp_users
Stores information about registered users.
Columns:
ID
โ Unique user ID (Primary Key)user_login
โ Username for loginuser_pass
โ Password (hashed)user_nicename
โ URL-friendly nameuser_email
โ Userโs emailuser_url
โ Userโs websiteuser_registered
โ Registration dateuser_activation_key
โ Key for account activation/password resetuser_status
โ Not commonly used (historical)display_name
โ Name displayed publicly
4. wp_usermeta
Stores metadata for users (roles, preferences, custom fields).
Columns:
umeta_id
โ Unique row IDuser_id
โ ID of the user (wp_users.ID
)meta_key
โ Key (e.g.,wp_capabilities
,wp_user_level
)meta_value
โ Value for the key (often serialized arrays)
5. wp_comments
Stores all comments left on posts/pages.
Columns:
comment_ID
โ Unique ID for each commentcomment_post_ID
โ ID of the post the comment belongs tocomment_author
โ Name of the commentercomment_author_email
โ Email address of commentercomment_author_url
โ Website of commentercomment_author_IP
โ IP address of commentercomment_date
โ Date/time of commentcomment_date_gmt
โ Date/time in GMTcomment_content
โ The actual comment textcomment_karma
โ Used for rating (not widely used)comment_approved
โ Approval status (1, 0, spam)comment_agent
โ User agent string (browser info)comment_type
โ Type (comment, pingback, trackback)comment_parent
โ ID of parent comment (for nested replies)user_id
โ ID of registered user (if commenter is logged in)
6. wp_commentmeta
Stores metadata for comments.
Columns:
meta_id
โ Unique row IDcomment_id
โ ID of the comment (wp_comments.comment_ID
)meta_key
โ Metadata key (e.g.,_akismet_result
)meta_value
โ Metadata value
7. wp_terms
Stores terms used for categories, tags, and custom taxonomies.
Columns:
term_id
โ Unique ID for the termname
โ Human-readable name (e.g., "Technology")slug
โ URL-friendly nameterm_group
โ Groups terms (rarely used)
8. wp_termmeta
Stores metadata for terms (extra info about categories/tags).
Columns:
meta_id
โ Unique row IDterm_id
โ ID of the term (wp_terms.term_id
)meta_key
โ Metadata keymeta_value
โ Metadata value
9. wp_term_taxonomy
Defines the taxonomy of a term (category, tag, or custom).
Columns:
term_taxonomy_id
โ Unique IDterm_id
โ ID of the term (wp_terms
)taxonomy
โ Type (category, post_tag, custom)description
โ Description of the termparent
โ Parent ID (for hierarchical taxonomies)count
โ Number of posts linked to this term
10. wp_term_relationships
Maps posts to terms.
Columns:
object_id
โ The ID of the object (usuallywp_posts.ID
)term_taxonomy_id
โ ID fromwp_term_taxonomy
term_order
โ Ordering (rarely used)
11. wp_options
Stores site-wide settings and plugin/theme configurations.
Columns:
option_id
โ Unique IDoption_name
โ Name of the option (e.g.,siteurl
,home
)option_value
โ Value of the option (often serialized arrays)autoload
โ Whether to autoload option (yes/no)
12. wp_links
Stores blogroll links (legacy feature). Still present for compatibility.
Columns:
link_id
โ Unique IDlink_url
โ URL of the linklink_name
โ Name of the linklink_image
โ Related image URLlink_target
โ Target attribute (_blank, _top)link_description
โ Description textlink_visible
โ Visibility (Y/N)link_owner
โ User ID of link creatorlink_rating
โ Rating (0โ10)link_updated
โ Last updated datelink_rel
โ Relationship valuelink_notes
โ Notes about the linklink_rss
โ RSS feed for the link

How WordPress Uses the Database
When a visitor opens your site:
- WordPress connects to the database using credentials in
wp-config.php
(DB_NAME
,DB_USER
,DB_PASSWORD
,DB_HOST
). - It runs SQL queries to fetch content (e.g., fetching post content from
wp_posts
). - PHP processes the query results.
- The theme (HTML + CSS) displays it in a user-friendly format.
Example Query:
SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post';
This fetches all published blog posts.
4. Common Database Operations
- Create โ Adding a new post, page, or user inserts data into tables
- Read โ Loading a page fetches data from
wp_posts
,wp_options
, etc. - Update โ Editing content updates existing rows
- Delete โ Removing content deletes rows or marks them as trash
5. Database Optimization & Maintenance
Since WordPress constantly interacts with the database, optimization ensures speed and security.
Best Practices
- Regularly clean up unused data (spam comments, revisions)
- Use a caching plugin (reduces database queries)
- Optimize tables with SQL or plugins like WP-Optimize
- Backup the database frequently
- Secure database access (strong passwords, change default
wp_
prefix)
6. Plugins & Custom Tables
Many plugins create their own tables to store data.
Example: WooCommerce creates tables for orders, products, and customers. Developers can also create custom tables for advanced needs.
7. Visualizing the Database Flow
Imagine the database as the heart of WordPress:
- Posts/Pages โ Stored in
wp_posts
- Settings โ Stored in
wp_options
- Users โ Stored in
wp_users
- Plugins/Themes โ Store settings in
wp_options
or custom tables - Categories/Tags โ Stored in
wp_terms
and linked viawp_term_relationships
Every request โ Goes through SQL โ Processed by PHP โ Displayed via theme
In Summary
The WordPress database is a structured storage system that powers everything from posts and settings to users and plugins. Understanding its structure helps in troubleshooting, optimization, and advanced customization.