Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Preview doesn't work for Advanded Custom Fields #202

Closed
tobiasandersen opened this issue Jan 8, 2021 · 9 comments
Closed

Preview doesn't work for Advanded Custom Fields #202

tobiasandersen opened this issue Jan 8, 2021 · 9 comments

Comments

@tobiasandersen
Copy link

tobiasandersen commented Jan 8, 2021

I'm not sure if this is a bug report or a feature request — but I'm trying to get preview data for a page with ACF content, but I'm only able to retrieve non-ACF data. Given this query:

page(id: $id, idType: $idType) {
  preview {
    node {
      pageTemplate {
        template {
          ... on Page_Pagetemplate_Template_Hero {
            headline
          }
        }
      }
      title
      isPreview
      modified
    }
  }
}

The three bottom fields (title, isPreview and modified) all give me the expected preview data — but any data inside pageTemplate (set up in ACF) is stale. So in this case the headline property will never show the preview data.

For reference, I'm using Wordpress 5.6 and the following plugins:

  • WPGraphQL for Advanced Custom Fields (0.4.0)
  • WP GraphQL (1.1.1)
  • Advanced Custom Fields PRO (5.9.3)
@jasonbahl
Copy link
Contributor

@tobiasandersen are you using Gutenberg or Classic Editor?

@tobiasandersen
Copy link
Author

@tobiasandersen are you using Gutenberg or Classic Editor?

Classic!

@tobiasandersen
Copy link
Author

tobiasandersen commented Jan 10, 2021

I'm not familiar with asPreview, but sounds like this could be the same issue as described in #190?

@tobiasandersen
Copy link
Author

The fix posted in #159 by @peteluffman seems to solve the issues I'm having as well.

@jasonbahl
Copy link
Contributor

@tobiasandersen I opened a PR which I believe might address this. Can you check #205 and let me know?

@tobiasandersen
Copy link
Author

Thanks @jasonbahl! Short answer: it didn't fix my issue, but also commented in the PR.

@TylerBarnes
Copy link
Collaborator

@tobiasandersen I think the problem here is the use of the preview field instead of using asPreview. Try this:

page(id: $id, idType: $idType, asPreview: true) {
      pageTemplate {
        template {
          ... on Page_Pagetemplate_Template_Hero {
            headline
          }
        }
      }
      title
      isPreview
      modified
}

@TylerBarnes
Copy link
Collaborator

@jasonbahl maybe the preview field should be deprecated?

@TylerBarnes
Copy link
Collaborator

Oh, nvm my bad, I see it's working for me on both:

Screen Shot 2021-01-15 at 4 48 20 PM

Screen Shot 2021-01-15 at 4 48 10 PM

This was referenced Jan 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants