wp_posts

The central content table storing all WordPress content including posts, pages, attachments, revisions, and custom post types.

Schema

ColumnTypeNullDefaultDescription
IDbigint(20) unsignedNOauto_incrementUnique identifier for the post
post_authorbigint(20) unsignedNO0User ID of the post author (FK → wp_users.ID)
post_datedatetimeNO0000-00-00 00:00:00Post creation date in local time
post_date_gmtdatetimeNO0000-00-00 00:00:00Post creation date in GMT
post_contentlongtextNONULLFull post content (HTML/blocks)
post_titletextNONULLPost title
post_excerpttextNONULLPost excerpt/summary
post_statusvarchar(20)NOpublishStatus: publish, draft, pending, private, trash, auto-draft, inherit
comment_statusvarchar(20)NOopenWhether comments allowed: open, closed
ping_statusvarchar(20)NOopenWhether pings allowed: open, closed
post_passwordvarchar(255)NOPassword for protected posts
post_namevarchar(200)NOURL slug
to_pingtextNONULLURLs to ping
pingedtextNONULLURLs already pinged
post_modifieddatetimeNO0000-00-00 00:00:00Last modification date (local)
post_modified_gmtdatetimeNO0000-00-00 00:00:00Last modification date (GMT)
post_content_filteredlongtextNONULLFiltered/processed content cache
post_parentbigint(20) unsignedNO0Parent post ID (FK → wp_posts.ID)
guidvarchar(255)NOGlobal Unique ID (permalink)
menu_orderint(11)NO0Order for pages/menu items
post_typevarchar(20)NOpostContent type: post, page, attachment, revision, nav_menu_item, or custom
post_mime_typevarchar(100)NOMIME type for attachments
comment_countbigint(20)NO0Cached comment count

Indexes

Key NameColumnsUniquePurpose
PRIMARYIDYesPrimary key
post_namepost_name(191)NoURL slug lookups
type_status_datepost_type, post_status, post_date, IDNoMain query index
post_parentpost_parentNoChild post queries
post_authorpost_authorNoAuthor archives
type_status_authorpost_type, post_status, post_authorNoAuthor + type queries

Foreign Key Relationships

  • post_authorwp_users.ID (author of the post)
  • post_parentwp_posts.ID (self-referential for hierarchical content)

Post Types Stored

TypeDescription
postBlog posts
pageStatic pages
attachmentMedia library items
revisionPost/page revisions
nav_menu_itemNavigation menu items
custom_cssCustomizer CSS
wp_navigationBlock-based navigation menus
Custom typesRegistered via register_post_type()

Post Statuses

StatusDescription
publishPublished and visible
draftNot published, visible to author
pendingAwaiting review
privateVisible only to logged-in users with permission
trashIn trash
auto-draftAuto-saved draft
inheritUsed by attachments/revisions (inherits parent status)
futureScheduled for future publication

Common Queries

Get published posts

sql
SELECT * FROM wp_posts 
WHERE post_type = 'post' 
  AND post_status = 'publish' 
ORDER BY post_date DESC 
LIMIT 10;

Get post with author info

sql
SELECT p.*, u.display_name, u.user_email 
FROM wp_posts p
JOIN wp_users u ON p.post_author = u.ID
WHERE p.ID = 123;

Get post by slug

sql
SELECT * FROM wp_posts 
WHERE post_name = 'my-post-slug' 
  AND post_type = 'post'
  AND post_status = 'publish';

Get child posts (attachments)

sql
SELECT * FROM wp_posts 
WHERE post_parent = 123 
  AND post_type = 'attachment';

Count posts by type and status

sql
SELECT post_type, post_status, COUNT(*) as count 
FROM wp_posts 
GROUP BY post_type, post_status 
ORDER BY count DESC;

Get revisions for a post

sql
SELECT * FROM wp_posts 
WHERE post_parent = 123 
  AND post_type = 'revision' 
ORDER BY post_modified DESC;

WordPress API Functions

  • get_post() – Retrieve post by ID
  • get_posts() – Get posts matching criteria
  • WP_Query – Full query class
  • wp_insert_post() – Insert new post
  • wp_update_post() – Update existing post
  • wp_delete_post() – Delete post
  • get_post_field() – Get specific field value