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

Fill in PHP field registration in README #186

Closed
wdews opened this issue Nov 10, 2020 · 7 comments
Closed

Fill in PHP field registration in README #186

wdews opened this issue Nov 10, 2020 · 7 comments

Comments

@wdews
Copy link

wdews commented Nov 10, 2020

In the readme.md file, the section titled Registering Fields in PHP trails off with a @todo annotation.

Could somebody please fill in this section?

@khaosophy
Copy link
Contributor

khaosophy commented Mar 3, 2021

I second this. I'm trying to figure out how add PHP-produced ACF fields to the GraphQL. If anyone can point me in the right direction, I'd be happy to write up the README once I figure it out.

@arnespremberg
Copy link

arnespremberg commented Mar 16, 2021

In the issue I link below it's mentioned that this is currently under development. However it appears you need to add an entry 'show_in_graphql' to the field group array and set it to 1. additionally it seems you could add a 'graphql_field_name' value.

However I haven't tested that yet

#188

@arnespremberg
Copy link

Please see the following code snippet that worked for me.

acf_add_local_field_group(array(
	'key' => 'test_group',
	'title' => 'test_group',
	'fields' => array(
		array(
			'key' => 'test_field,
			'label' => 'test_field',
			'name' => 'test_field',
			'type' => 'text',
			'show_in_graphql' => 1,
		),
	),
	'location' => array(
		array(
			array(
				'param' => 'post_type',
				'operator' => '==',
				'value' => 'post',
			),
		),
	),
	'show_in_graphql' => 1,
	'graphql_field_name' => 'testfield',
));

@wdews
Copy link
Author

wdews commented Mar 17, 2021

@arnespremberg the concern was not that I couldn't get this approach working, but that this was not documented in the README to prevent having to essentially reverse engineer the plugin in order to understand how to surface fields correctly.

@arnespremberg
Copy link

@wdews
If I find the time and the maintainers are happy with it I'll make a PR with a small paragraph about it. Maybe you got the time to do it right away?

Oh, and by the way, there was another person in this issue that seemed to struggle with finding the right option.

@khaosophy
Copy link
Contributor

I'm gonna fiddle with it this afternoon (or potentially into tomorrow) to confirm it works and I'll put in a PR with the update. It occurs to me my issue was more along the lines of custom post types, but those CPTs did have custom fields. Honestly they seemed to work pretty much out of the box, but I'm setting up an instance from scratch to confirm.

@jasonbahl
Copy link
Contributor

Closed by #235

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

No branches or pull requests

5 participants