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

ACF Doesn't appear in schema when AND operator is used in Location #206

Closed
sarahannnicholson opened this issue Jan 15, 2021 · 6 comments
Closed
Labels
Location Rules Issues related to ACF Location Rules

Comments

@sarahannnicholson
Copy link

sarahannnicholson commented Jan 15, 2021

I've encountered a bug while trying to switch over from the REST API to the GraphQL one. We have a few Advanced Custom Fields that have more than 1 condition on them. I've noticed adding the AND operator in the location part of the Field Group causes it to no longer render in the schema.

Repro steps:

  1. Create a basic FIeld Group. For example like this
    image
  • ensuring that the Show in GraphQL at the bottom is toggled on
  • ensuring that the GraphQL Field Name is set. For instance mine is acf
  1. Go into the grapiQL editor and query for pages. It might look something like this:
  pages{
    edges{
      node{
        acf {
          someBoolean
        }
        title
      }
    }
  }
}
  1. Now go back to your acf field and add an AND to your location. For example:
    image
    AND page type is equal to front page
    ** Note it could be any AND operator, I've tried many

  2. Go back to graphiQL and notice the schema no longer has the acf field you've made. If you try to run the query you get an error (as expected the schema doesn't exist)
    image

Notes

  • I do have a Front page set in my application
    image

  • Posts seem to be fine with the AND operator, it just seems to be pages for me.

  • Or operator seems to work fine for pages

Versions

WordPress: v5.6
Advanced Custom Fields: v5.9.4
WP GraphQL: v1.1.2
WPGraphQL for Advanced Custom Fields: v0.3.4

May be related to:
#76

@tim9009
Copy link

tim9009 commented Jan 22, 2021

I have the same issue. Having to apply every single field to all pages makes the admin UI very messy. Is there any known solution or fix/hack for this? This is holding my current project back, and I can imagine this is something almost every user of this plugin will bump in to at some point. Thank you! 🙂

@stupearce
Copy link

same here, we need to apply fields based on post type and category

@stupearce
Copy link

Actually its nothing to do with the 'And', the code has a flaw as it uses the underlying acf api calls, internally these rely on the current screen which is obviously inappropriate, the post type is the only rule you can rely on (which makes sense) except that any other rules fail which causes the acf_filter_field_groups fn to wipe out the field group (all rules must match). @jasonbahl I have re-coded 'add_acf_fields_to_post_object_types()' in class-config.php with a potential fix if you are interested. :-)
class-config.txt

@prock13
Copy link

prock13 commented Feb 12, 2021

Actually its nothing to do with the 'And', the code has a flaw as it uses the underlying acf api calls, internally these rely on the current screen which is obviously inappropriate, the post type is the only rule you can rely on (which makes sense) except that any other rules fail which causes the acf_filter_field_groups fn to wipe out the field group (all rules must match). @jasonbahl I have re-coded 'add_acf_fields_to_post_object_types()' in class-config.php with a potential fix if you are interested. :-)
class-config.txt

Thank you...your class-config file fixed the issue for me! 🥇

@jasonbahl jasonbahl added the Location Rules Issues related to ACF Location Rules label Mar 5, 2021
@jasonbahl jasonbahl added this to the ACF Schema Location Rules milestone Mar 5, 2021
@arnespremberg
Copy link

Will there be an update to this any time soon? Are you open for PRs?

I need to update a site to Gatsby v3 but currently can't due to this issue. Thanks!

@jasonbahl
Copy link
Contributor

This is addressed by #250.

With Release/v0.5.0, the field group rules are more broadly supported, and there's a new UI that allows you to override the location rules if the auto-mapping doesn't quite do what you need.

For this specific rule, the auto-mapping of Location Rules to GraphQL Types is difficult to translate.

The post_type === * rule can conflict with the page_type === * rule, so this rule will not show in the Schema by default, but you can manually set the field group to show on the Page type in the Schema, as seen below:

Screen Shot 2021-04-20 at 2 17 55 PM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Location Rules Issues related to ACF Location Rules
Projects
None yet
Development

No branches or pull requests

6 participants