-
Notifications
You must be signed in to change notification settings - Fork 122
Preview not working using page id, idType, asPreview:true #292
Comments
Hi There, Is there an update on this? Many thank. |
We were having similar issues with our set up and it's namely due to post_meta ( which is where ACF fields are stored ) fields being available in autosaves. I ended up writing a script to trigger an autosave on new posts / pages / custom post types and writing postmeta to the generated autosave's postmeta using the ACF Javascript API. I'm sure it can get far more complex than our specific use case (we have repeaters being used in several places), but it seemed to do the trick. I think with your scenario, it would be relatively easy to implement something similar. |
@DerthVedder can you show how this is setup, looking for a workaround for the same issue. For me any acf fields return null or defaults when using |
Thank you for getting back to me @DerthVedder and sorry for the long delay in doing so. If it is possible to see a sample of the code you used to set this up that would be great. In the meantime I will look into the ACF Javascript API and postmeta. |
@jasonbahl @mattLaakvand I'm still getting null from a simple ACF field if I use
|
@eliawk I'm getting null on a post field on fresh wp install.
|
I am actually getting null the same as @eliawk on essentially any query (as far as I can tell) when using asPreview. Still debugging and looking for a conflict etc, but thus far I have not found a way to make it work. |
Hi, same issue |
We've encountered the same issue. When previewing an already-published post, the ACF values populate normally. As soon as I make an edit to the post title/content, and preview again, the ACF fields in the GraphQL response are @jasonbahl I've set up a minimal reproduction of this here: https://github.com/missionmike/wordpress-acf-wpgraphql-preview-bug-minimal-reproduction I'm currently looking into the codebase for WPGraphQL and the WPGraphQL ACF plugin to see if it's something that can be fixed there.. If anyone has any pointers of where I should look, please let me know! So far, I'm checking in the CC @salim523 UpdateI can reference the original ACF values as a temporary workaround, but it doesn't allow us to preview any ACF changes. Perhaps this is due to an underlying issue with ACF + Gutenberg itself. If I add this snippet:
before this line: wp-graphql-acf/src/class-config.php Line 455 in 05636ef
... I can at least reference the original ACF values. I'm not thinking this is any kind of real solution, but just a clue/breadcrumb for reference. I'll provide an update if we come up with a more reasonable idea. Thanks for all your work on WPGraphQL! |
👋🏻 sorry for the lack of attention on this issue. This PR on core WPGraphQL that resolves some bugs around the If the changes from the above PR do not resolve the issue, then my next question would be: Are you using ACF with Gutenberg or Classic Editor? There's a core WordPress issue that prevents meta from being previewed when using Gutenberg (even in non-headless WordPress). You can read my comment on the Gutenberg issue here: WordPress/gutenberg#16006 (comment) For those that are NOT using Gutenberg, and the above changes to core WPGraphQL don't fix things for you, I recommend you try the new version of WPGraphQL for ACF that we're building over here: https://github.com/wp-graphql/wpgraphql-acf It is a complete re-architecture, and there are breaking changes, but it's the version we'll be going stable with and supporting long-term. It's solved a lot of bugs during the re-architecture, but if for some reason this feature is still not working on the new version, I'd recommend opening a new issue on that repo with detailed steps to reproduce. (and note whether you've tried the changes from the core WPGraphQL PR linked above and whether you're using Gutenberg or not) |
fwiw: WPGraphQL v1.18.0 was released yesterday which includes the |
related: wp-graphql/wpgraphql-acf#118 |
Currently using wp-graphql/wp-graphql version 1.18.2, and also have the WPGraphQL for Advanced Custom Fields version 0.6.1. Running WP as headless and trying to get Preview working. I dont have any ACF setup yet, just a regular page I've created. The page has been published, and then I try to edit the title and then click Preview without any other actions involved. On my frontend (nextjs) I do the following query to fetch the entry data:
But I get null as a response for that. If I skip "asPreview" I get the version for the published one. Do we have any updates on this? |
@clieee are your GraphQL requests authenticated when using if you're not authenticated, then a Just like in monolithic WordPress, WPGraphQL previews are only returned to authenticated users that have appropriate capabilities to be able to preview data. |
that explains it I guess, thanks for letting me know. Is there a token you can pass along, or what is there to setup this? |
👋 Hello, I've opened this issue to track documenting preview better. I believe this issue might be related to either a known bug with the block editor or possibly mis-configuration of Authorization / Authentication. I'll write up a guide that details how Preview is expected to work in WPGraphQL (and WPGraphQL for ACF). I'm going to close this issue as I've not been able to reproduce and recent activity seems to confirm my suspicions that Auth might be the culprit in some cases. |
We have been working on generating the page preview for a project created in NextJs and have all of the main functionality build for this but we have hit a bit of a brick wall due to this plugin. The latest version still has problems with ACF data not showing when using Grapqhl’s preview argument.
As an example, we have attached the Careers page templates query for a website we are working on, with the preview argument. Currently, graphql queries using the idType argument URI doesn't work with preview mode either.
The code we have written will enable NextJs' preview mode when browsing the API route and a secure token gets passed as URL parameters, which then redirect you to the correct location.
After being redirected the page will get generated as a preview on the server which will be served to the client. This gets done by converting the URL to the database ID and passing asPreview boolean argument as true, which then gets the latest revision of the page. (a revision gets created when clicking preview)
This then generates a query as below:
This works great when making changes to the title or standard Wordpress content boxes, but due to the bug in Graphql ACF those fields remain empty. Since all the pages are 95% made up of ACF data, preview won't be usable without this working.
This is the resulting data from the query above though the id is fake:
The text was updated successfully, but these errors were encountered: