WordPress: Version 5.3.2
WPGraphQL: Version 0.6.3
WPGraphQL ACF: Version 0.3.1
Advanced Custom Fields Pro: Version 5.8.7
I'm currently trying to query revisions to set up WP previews. When I query normal revisions they have all of the data I expect, but the preview revision doesn't have any acf data at all. All acf fields are null or just an empty array for flexible content. It seems like normal WP fields work fine. I just tested title and content here.
My test query:
{
revisions(first: 2) {
nodes {
__typename
... on Page {
title
content
id
databaseId
acfFields {
text
repeater {
item
}
flexibleContent {
... on Page_Acffields_FlexibleContent_Text {
text
}
... on Page_Acffields_FlexibleContent_Image {
image {
uri
}
}
}
}
}
}
}
}
_The first item in the response is the preview revision and the second item is a regular revision._
response:
{
"data": {
"revisions": {
"nodes": [
{
"__typename": "Page",
"title": "Sample PREVIEW Page",
"content": "\n<p>This is the preview revision of my sample page!!!!! (please work)</p>\n",
"id": "cmV2aXNpb246MTY=",
"databaseId": 16,
"acfFields": {
"text": null,
"repeater": null,
"flexibleContent": []
}
},
{
"__typename": "Page",
"title": "Sample Page",
"content": "\n<p>This is my sample page!</p>\n",
"id": "cmV2aXNpb246MTU=",
"databaseId": 15,
"acfFields": {
"text": "This is some regular text",
"repeater": [
{
"item": "repeater item 1"
},
{
"item": "repeater item 2"
},
{
"item": "repeater item 3"
}
],
"flexibleContent": [
{
"text": "this is flexible content text~!!"
},
{
"image": {
"uri": "sample-page/aditya-chinchure-2yrocbpcvey-unsplash/"
}
}
]
}
}
]
}
}
}
You can reproduce this by adding some acf fields to your page, clicking the preview button to generate the preview revision, then querying for your page revisions.
I just put together a very minimal reproduction of this. Here is the acf field group import json file.
acf-export-2020-02-22.json.zip
@CalebBarnes thanks so much for the detailed issue. The information provided should allow me to reproduce the issue and get a better idea if it's a core WPGraphQL issue we're dealing with, a WPGraphQL for ACF issue, or something else.
I'll try to look into this early next week and follow-up.
Thanks!
@CalebBarnes the upcoming v0.10.0 release (#1337) addresses previews / revisions across the board.
Revisions (including previews) will resolve fields such as connections to terms, author, comments, etc using the data from the parent (published) node. Then, under the hood, get_post_meta() is being filtered to also default to using meta from the parent node for revisions, since meta isn't revised by default in WordPress.
There is a filter added graphql_resolve_revision_meta_from_parent which allows plugins such as ACF to override and allow meta of specific keys (or other criteria) to resolve using the revision node instead of the parent node.
So now we'll be able to see revisions as a mix of revised data and published data, much like how you see it when looking at a preview in WordPress.
@CalebBarnes Here's more information about this: https://github.com/wp-graphql/wp-graphql/issues/1312#issuecomment-638882448
I've got some work to do on the ACF side before I can get a demo to show. I'll try and have something shortly. 馃槃
@CalebBarnes Here's more information about this: #1312 (comment)
I've got some work to do on the ACF side before I can get a demo to show. I'll try and have something shortly. 馃槃
Whats the status on this? When trying to preview existing posts only 1 out of 10 different ACF fields returns its value. Others just return null. It works fine on drafts. Is there something I am missing here?
Most helpful comment
@CalebBarnes the upcoming v0.10.0 release (#1337) addresses previews / revisions across the board.
Revisions (including previews) will resolve fields such as connections to terms, author, comments, etc using the data from the parent (published) node. Then, under the hood,
get_post_meta()is being filtered to also default to using meta from the parent node for revisions, since meta isn't revised by default in WordPress.There is a filter added
graphql_resolve_revision_meta_from_parentwhich allows plugins such as ACF to override and allow meta of specific keys (or other criteria) to resolve using the revision node instead of the parent node.So now we'll be able to see revisions as a mix of revised data and published data, much like how you see it when looking at a preview in WordPress.