How Does WordPress Store Previews?

Have you ever thought about how WordPress previews work? If the lack of resources on this topic is any indication, the answer is probably no. After all, they just kind of work. Themes and plugins generally don’t have to worry about how preview data stored or how to retrieve it because WordPress injects it automatically.

I had never needed to worry about preview data either until recently. I was digging into a bug in WPGraphQL related to queries for preview data and found that I needed a better understanding of how preview data is stored under various conditions. Things like the current status or revisions support of a post can affect the outcome of user actions like “Preview Changes”, “Save draft”, or “Publish”. After a little testing and observation, I ended up with this chart.

Flowchart showing where preview data is stored iand sourced in WordPress
Differences in post status, user actions, and revision support can all influence how WordPress stores and sources preview data.

It’s worth noting that autosaves are just a special type of revision. They exist for all post types regardless of whether the post type enables revision support. Autosaves also use a different value for post_name. While regular revisions use {$post_id}-revision-v1 as their post_name, autosaves use {$post_id}-autosave-v1. Other than that, they are pretty much the same!