CoachingUgosay

WordPress Database Structure and Tables

Gokila Manickam

Gokila Manickam

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 to wp_users.ID)
  • post_date โ€“ Date and time when the post was created
  • post_date_gmt โ€“ Same as above, in GMT
  • post_content โ€“ Main content of the post/page
  • post_title โ€“ Title of the post
  • post_excerpt โ€“ Short summary or excerpt
  • post_status โ€“ Status (e.g., publish, draft, trash)
  • comment_status โ€“ Whether comments are allowed (open/closed)
  • ping_status โ€“ Whether pingbacks/trackbacks are allowed
  • post_password โ€“ Password for password-protected posts
  • post_name โ€“ URL-friendly slug
  • to_ping โ€“ Sites to ping
  • pinged โ€“ Sites that have been pinged
  • post_modified โ€“ Last modified date/time
  • post_modified_gmt โ€“ Last modified date/time in GMT
  • post_content_filtered โ€“ Used internally for filtered content
  • post_parent โ€“ ID of parent post (for page hierarchy, attachments)
  • guid โ€“ Unique reference link (often used for media attachments)
  • menu_order โ€“ Order of pages in menus
  • post_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 row
  • post_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 login
  • user_pass โ€“ Password (hashed)
  • user_nicename โ€“ URL-friendly name
  • user_email โ€“ Userโ€™s email
  • user_url โ€“ Userโ€™s website
  • user_registered โ€“ Registration date
  • user_activation_key โ€“ Key for account activation/password reset
  • user_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 ID
  • user_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 comment
  • comment_post_ID โ€“ ID of the post the comment belongs to
  • comment_author โ€“ Name of the commenter
  • comment_author_email โ€“ Email address of commenter
  • comment_author_url โ€“ Website of commenter
  • comment_author_IP โ€“ IP address of commenter
  • comment_date โ€“ Date/time of comment
  • comment_date_gmt โ€“ Date/time in GMT
  • comment_content โ€“ The actual comment text
  • comment_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 ID
  • comment_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 term
  • name โ€“ Human-readable name (e.g., "Technology")
  • slug โ€“ URL-friendly name
  • term_group โ€“ Groups terms (rarely used)

8. wp_termmeta

Stores metadata for terms (extra info about categories/tags).

Columns:

  • meta_id โ€“ Unique row ID
  • term_id โ€“ ID of the term (wp_terms.term_id)
  • meta_key โ€“ Metadata key
  • meta_value โ€“ Metadata value

9. wp_term_taxonomy

Defines the taxonomy of a term (category, tag, or custom).

Columns:

  • term_taxonomy_id โ€“ Unique ID
  • term_id โ€“ ID of the term (wp_terms)
  • taxonomy โ€“ Type (category, post_tag, custom)
  • description โ€“ Description of the term
  • parent โ€“ 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 (usually wp_posts.ID)
  • term_taxonomy_id โ€“ ID from wp_term_taxonomy
  • term_order โ€“ Ordering (rarely used)

11. wp_options

Stores site-wide settings and plugin/theme configurations.

Columns:

  • option_id โ€“ Unique ID
  • option_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 ID
  • link_url โ€“ URL of the link
  • link_name โ€“ Name of the link
  • link_image โ€“ Related image URL
  • link_target โ€“ Target attribute (_blank, _top)
  • link_description โ€“ Description text
  • link_visible โ€“ Visibility (Y/N)
  • link_owner โ€“ User ID of link creator
  • link_rating โ€“ Rating (0โ€“10)
  • link_updated โ€“ Last updated date
  • link_rel โ€“ Relationship value
  • link_notes โ€“ Notes about the link
  • link_rss โ€“ RSS feed for the link
database-structure-explained

How WordPress Uses the Database

When a visitor opens your site:

  1. WordPress connects to the database using credentials in wp-config.php (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST).
  2. It runs SQL queries to fetch content (e.g., fetching post content from wp_posts).
  3. PHP processes the query results.
  4. 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 via wp_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.

More articles

HTML Attributes and Techniques for Web Performance

Speed up your site using HTML attributes like preload, preconnect, prefetch, async, defer, fetchpriority, and lazy loading to boost UX and SEO

Read more

WordPress Plugins 2025 โ€“ Must-Have Tools for Developers

Discover 8 essential WordPress plugins 2025 for developers. Boost performance, SEO, design, security, and e-commerce with these top tools.

Read more

Connect with Us

Got questions or need help with your project? Fill out the form, and our team will get back to you soon. Weโ€™re here for inquiries, collaborations, or anything else you need.

Address
12, Sri Vigneshwara Nagar, Amman Kovil
Saravanampatti, coimbatore, TN, India - 641035