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

added docs for registering fields with php #235

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,41 @@ Setting the value of this field to "Yes" will show the field group in the WPGrap

##### Registering Fields in PHP

When registering ACF Fields in PHP, `@todo`
When registering ACF Fields in PHP, you need to add `show_in_graphql` and `graphql_field_name` when defining your field group. See below as an example.

```
function my_acf_add_local_field_groups() {

acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'My Group',
'show_in_graphql' => true,
'graphql_field_name' => 'myGroup',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));

}

add_action('acf/init', 'my_acf_add_local_field_groups');
```

Each individual field will inherit its GraphQL name from the supplied `name` tag. In this example, `sub_title` will become `subTitle` when requested through GraphQL. If you want more granular control, you can pass `graphql_field_name` to each individual field as well.

## Supported Fields

Expand Down