Skip to content

Instantly share code, notes, and snippets.

@izzygld
Created June 25, 2018 14:22
Show Gist options
  • Save izzygld/df0445396ca708ec53296cfcdf30ba0a to your computer and use it in GitHub Desktop.
Save izzygld/df0445396ca708ec53296cfcdf30ba0a to your computer and use it in GitHub Desktop.
Hooking up ACF repeater fields to the shema.
//acf stats repeater
array (
'key' => 'field_5a27ee3a83076',
'label' => 'Stats',
'name' => 'stats',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => '',
'sub_fields' => array (
array (
'key' => 'field_5a27ee4683077',
'label' => 'Label',
'name' => 'label',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array (
'key' => 'field_5a27ee4c83078',
'label' => 'Value',
'name' => 'value',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
),
//make sure to use ObjectType
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
// stats repeater
add_action('graphql_stats_fields', function($fields) {
$statsType = new ObjectType([
'name' => 'Stat',
'description' => __( 'The description of your process type', 'your-textdomain' ),
'fields' => [
'project__Label' => [
'type' => WPGraphQL\Types::string(),
],
'projects__value' => [
'type' => WPGraphQL\Types::string(),
]
]
]);
$fields[ 'stats' ] = [
'type' => Type::listOf($statsType),
'description' => __( 'Your processes repeater field in GraphQL', 'your-textdomain' ),
'resolve' => function( \WP_Post $post ) {
$fp_metabox_process_group = get_post_meta( $post->ID, 'fp_metabox_process_group', true );
return ! empty( $fp_metabox_process_group ) ? $fp_metabox_process_group : null;
},
];
return $fields;
},99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment