I have a site using the WordPress REST API and advanced custom fields ACF. I use the plugin ACF TO REST API to expose the AC fields to the REST API. So far so good.
But now I want to add normal functionality to the «Preview Changes» button within the wordpress backend. I managed to change the buttons functionality and I also learned that pushing it does autosave the post into a new revision. To access and display the preview I must get the data of the newest revision of the post. I can do that but the REST API does only expose core wordpress stuff (like title, content, excerpt etc.) but not the ACFs belonging to that post.
I would like to access a wordpress REST API route to get the newest revision of the post including the content of the (changed) ACF fields.
Could somebody help me out how to write a custom route which does exactly that? I tried to add this functionality to the ACF TO REST API plugin, but so far I had no success.
I think I have call a REST API route where I include the posts (or pages) id, then it makes a call returning me the revisions of that page (which i already get here > wp/v2/pages/51/revisions/
,
This shows me an array of revision-entries like this:
{
"author": 1,
"date": "2017-11-17T18:19:51",
"date_gmt": "2017-11-17T17:19:51",
"id": 461,
"modified": "2017-11-17T18:19:51",
"modified_gmt": "2017-11-17T17:19:51",
"parent": 51,
"slug": "51-autosave-v1",
"guid":
{
"rendered": "http://[DOMAIN]/51-autosave-v1/"
},
"title":
{
"rendered": "post title"
},
"content":
{
"rendered": "post content"
},
"excerpt":
{
"rendered": ""
},
"_links":
{
"parent": [
{
"href": "http://[DOMAIN]/api/wp/v2/pages/51"
}]
}
},
but now I only want the newest revision. The newest revision seems to be like a normal post and has a normal post ID (I call it RevisionID, which would be 461
in the example above).
Then I need to query all the post_meta entries with 'post_id' = RevisionID
and merge the results with the results from the newest revision.
Can someone confirm that?
I also would be very glad with some help how I can set up the queries for the Wordpress REST API to filter the results I want.
thanks for any help here.
Cheers