Support » Developing with WordPress » Preview Changes in REST API

  • Resolved jvke

    (@jvke)


    Hi all!

    I’m having difficulty finding any documentation around the ‘Preview Changes’* functionality, and whether this is available in REST API without a lot of custom work.

    * I’m talking about the ‘preview’ button, used for looking at your new/edited content before publishing it for public viewers to see.

    Thanks for any assistance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @jvke,

    Are you talking about in the case where you are building a JavaScript based theme that pulls its data from the API? This will require some extra work.

    WordPress stores the post data in a temporary ‘autosave’ revision when you click the preview button: you will need to alter or filter your endpoint return to use the revision data instead of the post data to display the preview. You can do this by adding a custom route with for ‘{route}/preview’, which adds a query var. the data endpoint responds to this by grabbing the autosave with ‘wp_get_post_autosave’ and returning the data from the revision.

    Thanks a lot, that’s a great solution. Much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Preview Changes in REST API’ is closed to new replies.