-
Notifications
You must be signed in to change notification settings - Fork 121
ACF Location screen context now has "wp-graphql-acf" set to true, thi… #134
base: develop
Are you sure you want to change the base?
Conversation
…s allows overriding of locations validation"
@AbeCole I've been discussing in Slack with some folks revamping how Field Groups can be assigned to the Schema. I opened this issue to explain further: #135 The plan is to no longer make use of the location rules at all, but set a more explicit relationship between Field Groups and the WPGraphQL Schema. |
Does this work around still work? I added the code snippet to my theme but still not seeing the graphql fields when using multiple acf location rules. Is there any other way to get around say showing a field on all pages except the home page? |
@moxdev It still works for me however you need to add additional 'add_filter' hooks depending on which 'location rules' you are using. The example you've quoted will only override the 'page_template' rule. If you are using multiple, for example lets say you have a field group with a 'page_template' & 'post format' & 'post taxonomy' rules, you need to add multiple hooks like so:
|
Ive tried everything I can think of cant get "page_template" to work. Doesn't seem to ignore any rules I set "post_format" "post_taxonomy" etc. Show in GraphQL is on for all fields and tried changing the "GraphQL Field Name" thinking maybe it was caching it. Im using the latest version of all the plugins. Any other ideas? |
The 'page_template' rule I've added as an example, if the field group you are trying to display doesn't use that rule then you don't need to add the filter like I have (instead you hook a different action). If you can provide a screenshot of the rules for the field group you are trying to get then I can tell you which actions would need to be hooked. I can't understand exactly where your at (if you have source code I can see it will be a lot easier to help). Have you actually made the changes in this commit? I.e. adding 'add_wp_graphql_acf_to_acf_screen', 'get_acf_field_groups' and related changes to |
My mistake I missed a line in the commit got it working now thanks for the help! |
This allows for location rule validation for Field Groups to be overridden, allowing certain location rules that are not relevant to GraphQL to be ignored.
For example currently 'page template' rules will never return 'true' (thus hiding any Field Groups that have these rules set from displaying in GraphQL), we can use the ACF filter
acf/location/rule_match/$rule_param
:Probably be good to add this example to documentation but maybe someone else has changes to the format I've added.