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

Dynamically check field groups against visibility conditions #65

Closed
cjkoepke opened this issue Sep 25, 2019 · 3 comments
Closed

Dynamically check field groups against visibility conditions #65

cjkoepke opened this issue Sep 25, 2019 · 3 comments
Labels
Location Rules Issues related to ACF Location Rules

Comments

@cjkoepke
Copy link

@jasonbahl There may be a way around this, but I noticed that the registering if field groups within WPGraphQL is a bit limited. For instance:

https://github.com/wp-graphql/wp-graphql-acf/blob/release/v0.2.1/src/class-config.php#L142-L146

This section checks if the post_type is equal to a page, but I have two conditions on this particular Field Group:

  1. Is of post type page
  2. Is a specific page template.

This seems more like a limitation of ACF, but when running acf_get_field_groups( [ 'post_type' => 'page' ] ), field groups with ONLY that condition show. If there are more conditions (such as a page template type), the function returns empty.

I need ACF fields added to the GraphQL Schema of a page that is also a specific template. For now, it seems like I may have to add these myself? Please let me know if I'm doing something wrong or if this is a known limitation.

Thanks!

@cjkoepke
Copy link
Author

One suggestion here would be to reverse the process of lookup. i.e. Loop through all the Fields Groups and add their values to the post/page that matches the visibility conditions.

@intelligence
Copy link

I'd be interested to see how you get around this issue, if you find a good way to do it!

@jasonbahl jasonbahl added the Location Rules Issues related to ACF Location Rules label Feb 24, 2020
@jasonbahl jasonbahl added this to the ACF Schema Location Rules milestone Mar 30, 2021
@jasonbahl
Copy link
Contributor

👋🏻 with v0.5.0 the Location Rules have been COMPLETELY re-worked.

You can see a video walking through this here: https://www.youtube.com/watch?v=VvrZGrcwv0Y

There's a new LocationRules class that determines the Location Rules for all field groups, or for a specified field group.

You can pass a field group config array to the class constructor and it will determine the location rules.

You can see this in action in the ajax callback (https://github.com/wp-graphql/wp-graphql-acf/pull/250/files#diff-dd5fea25d81c573ef9bd5ea222e904faa6f4c52d6683c9f71d0255eb0ba6505eR63-R64) that's used with the new settings fields, as demonstrated in the video.

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

3 participants