The WordPress Database Structure Explained
A guided tour of the WordPress database: the 12 core tables, how posts, meta, terms, users, options and comments relate, multisite tables, and how to query them safely.

A standard WordPress site stores everything in 12 MySQL tables: wp_posts and wp_postmeta for all content, wp_terms, wp_term_taxonomy, wp_term_relationships and wp_termmeta for categories and tags, wp_users and wp_usermeta for accounts, wp_comments and wp_commentmeta for comments, wp_options for settings, and wp_links for the legacy link manager. Plugins add their own tables or reuse these. Understanding the relationships explains most performance problems and lets you query data safely.
The wp_ prefix is set by $table_prefix in wp-config.php; in code always use $wpdb->posts and friends rather than hard-coding it.
Content: wp_posts and wp_postmeta
wp_posts holds every piece of content, distinguished by post_type: posts, pages, attachments (media), revisions, navigation menu items, reusable blocks and patterns, templates in block themes, custom post types, WooCommerce orders on older setups, and more.
| Column | Meaning |
|---|---|
ID | Primary key |
post_author | User ID |
post_date / post_date_gmt | Publish date, local and UTC |
post_content, post_title, post_excerpt | The content (blocks are stored as HTML with comment delimiters) |
post_status | publish, draft, pending, private, future, trash, inherit |
post_name | The slug |
post_parent | Parent page, or the post an attachment/revision belongs to |
post_type | post, page, attachment, revision, nav_menu_item, your CPTs |
guid | A permanent identifier, not a URL to change |
wp_postmeta is a key-value store: meta_id, post_id, meta_key, meta_value. Custom fields, featured image IDs (_thumbnail_id), page templates (_wp_page_template) and most plugin data live here. Keys starting with an underscore are hidden from the Custom Fields box. See custom fields and post meta.
Taxonomies: four tables
wp_terms: the term itself (term_id,name,slug).wp_term_taxonomy: which taxonomy a term belongs to (category,post_tag,product_cat…), its description, parent and postcount.wp_term_relationships: links objects (posts) toterm_taxonomy_ids.wp_termmeta: extra data per term.
The split between terms and term_taxonomy is historical; in practice each term has one taxonomy row. Use the API (wp_get_post_terms(), get_terms()) instead of joining these by hand. See custom taxonomies.
Users: wp_users and wp_usermeta
wp_users stores login, hashed password, email, display name and registration date. Roles and capabilities are stored in wp_usermeta under {prefix}capabilities, along with preferences and plugin data. This is why changing the table prefix without updating these keys locks admins out (roles and capabilities).
Settings: wp_options
Site settings (siteurl, home, active_plugins, template), widget and theme settings, transients and countless plugin options live in wp_options. The autoload column decides whether an option is loaded into memory on every request. Large autoloaded data is one of the most common hidden performance problems (cleaning up autoload).
Comments: wp_comments and wp_commentmeta
Comments, pingbacks and, in some plugins, reviews and notes. comment_approved holds 1, 0, spam or trash. WooCommerce product reviews and some LMS features also use this table with their own comment_type.
wp_links
Left over from the old Blogroll; hidden since WordPress 3.5 and normally empty.
Multisite tables
A network adds global tables (wp_blogs, wp_site, wp_sitemeta, wp_signups, wp_registration_log, wp_blogmeta) and gives each site its own set of content tables with a number: wp_2_posts, wp_2_options. Users are shared across the network. See WordPress multisite.
Plugin tables
Larger plugins create their own tables for performance: WooCommerce (orders with HPOS, sessions, analytics lookups), Action Scheduler, form entries, LMS progress data and logs. Before deleting tables you do not recognize, check which plugin owns them.
Querying the database safely
- Prefer the APIs:
WP_Query,get_post_meta(),get_option(). They handle caching and filters (WP_Query guide). - When you need SQL, use
$wpdbwith table properties andprepare():
global $wpdb;
$ids = $wpdb->get_col( $wpdb->prepare(
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s",
'featured', '1'
) );
Never concatenate user input into SQL. See using $wpdb safely.
Why the structure affects performance
meta_valueis not indexed, so filtering large meta tables is slow.- Revisions and auto-drafts can make
wp_postsmuch larger than the visible content. - Orphaned meta from deleted posts and expired transients accumulate.
- Autoloaded options load on every request.
Practical clean-up steps are in optimizing a WordPress database.
Common mistakes
- Editing serialized option values by hand (string lengths break); use WP-CLI or the API.
- Running search-replace in SQL on serialized data; use
wp search-replace. - Changing
guidvalues after a migration. - Deleting "unknown" tables without a backup.
Frequently asked questions
How many tables does WordPress have?
Twelve on a single site. Multisite adds network tables plus a set of content tables per site, and plugins add their own.
Where are WordPress pages stored?
In wp_posts, with post_type = 'page'.
Where are images stored?
The files are in wp-content/uploads. Each has a row in wp_posts (post_type = 'attachment') and metadata such as sizes in wp_postmeta.
Can I change the table prefix?
Yes, but you must rename tables and update prefixed keys in wp_options and wp_usermeta. It is a minor hardening step, not real security.
Conclusion
Most WordPress data reduces to posts with meta, terms linking to posts, users with meta, and options. Knowing that model makes debugging, migrations and performance work far easier. References: the Database Description and the wpdb class reference.
Database grown slow or messy? See our database optimization service.
Save this practical guide
Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.
