Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-source-wordpress] No Advanced Custom Fields (ACF) in GraphQL response #2394

Closed
akmur opened this issue Oct 8, 2017 · 12 comments · May be fixed by tejzpr/gatsby#21 or tejzpr/gatsby#28
Closed

Comments

@akmur
Copy link

akmur commented Oct 8, 2017

Hi,

I am trying build a Gatsby site by fetching data from WordPress.
ACF data seems to not be pulled.

I have a self hosted WordPress, I have set the "useACF: true" option .
If I understand correctly, I should now have access to "childWordpressAcfField" from GraphQL.

However I do not see it appearing in the GraphQL UI, and trying to query for it returns the error "Cannot query field "childWordpressAcfField" on type "wordpress__POST"

Any idea?

@akmur akmur changed the title No Advanced Custom Fields in GraphQL response [gatsby-source-wordpress] No Advanced Custom Fields (ACF) in GraphQL response Oct 8, 2017
@KyleAMathews
Copy link
Contributor

KyleAMathews commented Oct 8, 2017 via email

@akmur
Copy link
Author

akmur commented Oct 8, 2017

Hi, thanks for your answer.

I have been exploring the schema in graphiql quite a bit, and my problem is exactly that I don't see anything ACF related.

if I do:

wordpressPost {
    acf
}

I get an error, "Cannot query field "acf" on type "wordpress__POST".
If I explore using ctrl+enter, nothing related to ACF pops up.
ACF is active on the site, and everything is up to date.

I'm running out of ideas LOL :)

@KyleAMathews
Copy link
Contributor

Try installing the using-wordpress example site and poking around there.

@akmur
Copy link
Author

akmur commented Oct 8, 2017

Ok, I've tried the demo and it's got the acf fields as expected.
Then I tried to replace your WP site with mine in the gatsby-config (and also wiped all the templates of course). Then run gatsby develop, and graphiql is missing the acf fields! Argh!
Do you know which versions of WP and ACF you have on the site?
Thanks again

@EmilTholin
Copy link
Contributor

Do you have the acf-to-rest-api plugin installed on your site?

@akmur
Copy link
Author

akmur commented Oct 8, 2017

Hi Emil,

Yes I do, it's version 2.2.1 (latest).
I'm actually using it already on my current (PHP) website.

So weird!

@daviddeejjames
Copy link
Contributor

@akmur I am having similar issues with ACF and the wordpress-source plugin in general, do you have a repo for this project yet? Thinking of looking into it, which versions of ACF and Wordpress are you using as well?

In addition, I found that upgrading to the latest version of the wordpress-source forces you to use the acf{...} for the GraphQL schema but means it will not return anything unless you strictly go down to the level of say:

acf{
  my_repeater{
    title
    image
    url
  }
}

Let me know if any of that helps 😃

@garytokyo
Copy link

Just to join in here I cannot get ACF query to work on allWordpressPage just says "Cannot query field \"acf\" on type \"wordpress__PAGE\".", in graphiql. It used to work fine using childWordpressAcfField but that doesn't work at all in the latest version of wordpress source plugin. The docs still say to use that which is very misleading if this has been removed. I have tried working out how to use it from viewing the using wordpress example but I cannot see how to use it from this - maybe I am just stupid!

This is the query I tried (have also tried different variations):

allWordpressPage {
      edges {
        node {
          id
          title
          content
          excerpt
          slug
          status
          author {
            id
            name
          }
          featured_media
          menu_order
          acf {
            about {
              services
            }
          }
        }
      }
    }

Any help appreciated.

@akmur
Copy link
Author

akmur commented Oct 10, 2017

I think I will setup a test wordpress website and will let you know, I will push the code to github too

@pieh
Copy link
Contributor

pieh commented Oct 12, 2017

I had similiar problem. Do you guys use ACF as a plugin or do you include it in your theme functions.php ? It seems that including it in functions.php doesnt play well with acf-to-rest-api plugin (so its not related to gatsby-source-wordpress at all). If that's your setup then in functions.php manually init acf-to-rest-api plugin after including ACF:

include_once( get_stylesheet_directory() . '/acf/acf.php' );
ACF_To_REST_API::init();

Also first step would be inspecting wordpress api response (f.e /wp-json/wp/v2/posts) and see if results have acf field

@akmur
Copy link
Author

akmur commented Oct 13, 2017

No, I use it as a plugin - and in my case the api response does have the custom fields, as I'm already using them through JavaScript

@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants