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

Register fields with WP GraphQL #210

Open
troyblakelydc opened this issue Apr 28, 2023 · 2 comments
Open

Register fields with WP GraphQL #210

troyblakelydc opened this issue Apr 28, 2023 · 2 comments

Comments

@troyblakelydc
Copy link

I am trying to register custom fields to the wp-graphql plugin with ACF. Per the documentation, fields can be registered in PHP by adding:
'show_in_graphql' => true, 'graphql_field_name' => 'myGroup',

I added these attributes to the admin_cols collection of the custom post type using poet, and it doesn't seem to be recognized by wp-graphql. I'm not sure if this is an issue with poet, extended-cpts or wp-graphql, but any suggestions would be appreciated.

@johnbillion
Copy link
Owner

Did you put these fields at the top level of the arguments array used for the post type generation? They don't go into the admin_cols field.

@troyblakelydc
Copy link
Author

troyblakelydc commented May 4, 2023

We have a custom post type called "release" that we have flagged to 'show_in_graphql' as shown below. This successfully adds the custom post type to the GQL schema. Everything works there.

This is through poet, so I know it works a little differently, just hoping you might have an idea.

'post' => [
        'release' => [
            'supports' => ['title', 'thumbnail'],
            'show_in_rest' => true,
            'labels' => [
                'singular' => 'Release',
                'plural' => 'Releases',
            ],
            'admin_cols' => [...]
            ],
            'show_in_graphql' => true,
            'graphql_single_name' => 'release',
            'graphql_plural_name' => 'releases',
        ],

However, each custom field that you want exposed to the GQL schema also needs to be explicitly added. The documentation shows this being done as the field group is added to ACF. I'm not sure if/how this might map into poet. I tried adding it into the admin_cols section both as an attribute of admin_cols, and as attributes of a give field and neither one worked.

'admin_cols' => [
                'artist' => ['post_field' => 'artist', 
                'meta_key' => 'artist',
                'show_in_graphql' => true,
                'graphql_field_name' => 'artist_group',],
                ...
                ],
                'show_in_graphql' => true,
                'graphql_field_name' => 'admin_cols',
            ],

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

No branches or pull requests

2 participants