wp-graphql-acf
wp-graphql-acf copied to clipboard
mutation createPost don't support acf input field?
Hi. I use Wpgraphql and i have problem. how to defind custom acf type in input field?
I have a same question too. Can't find any info. @jasonbahl seems that creation and update is not supported by this plugin, isn't it?
Hey I have an example repository here wp-acf-mutations. Basically you need to run the filters to add the input fields to the schema based on your acf fields.
Hi @saleebm, many thanks for pointing me out. If ACF and CPT UI is present the problem solves in few lines of code in functions.php. It is amazing!
use WPGraphQL\AppContext;
use WPGraphQL\Model\User;
add_action( 'graphql_input_fields', function ( $fields, $type_name, $config ) {
if ( $type_name === 'UpdateArticlesInput') {
$fields = array_merge( $fields, [
'name' => [ 'type' => 'String' ],
] );
}
return $fields;
}, 20, 3 );
add_action( 'graphql_post_object_mutation_update_additional_data', function ( $post_id, $input, $mutation_name, $context, $info ) {
if ( isset( $input['name'] ) ) {
update_field('field_6036d0504e27d', $input['name'], $post_id);
}
}, 10, 5 );
Hello! Mutations are not currently on the near-term roadmap for this plugin. We do hope to add support in the future, but I don't know when. I've labeled this "Future Feature" and moved it to the "ACF Mutations" milestone for future consideration.
Hi @saleebm, many thanks for pointing me out. If ACF and CPT UI is present the problem solves in few lines of code in functions.php. It is amazing!
use WPGraphQL\AppContext; use WPGraphQL\Model\User; add_action( 'graphql_input_fields', function ( $fields, $type_name, $config ) { if ( $type_name === 'UpdateArticlesInput') { $fields = array_merge( $fields, [ 'name' => [ 'type' => 'String' ], ] ); } return $fields; }, 20, 3 ); add_action( 'graphql_post_object_mutation_update_additional_data', function ( $post_id, $input, $mutation_name, $context, $info ) { if ( isset( $input['name'] ) ) { update_field('field_6036d0504e27d', $input['name'], $post_id); } }, 10, 5 );
Where do you find the field_6036d0504e27d
in the database?
Ok I found it => in the wp_postmeta
table, search for _your_acf_field_slug
(add the _
at the beginning) in the meta_key
column, and take the corresponding meta_value
.
Thanks a lot @Yuribtr! You solved my dead end!
👋🏻 We are re-building WPGraphQL for ACF over here: https://github.com/wp-graphql/wpgraphql-acf.
I've created a new issue to track mutation support (and explain some current blockers). see: https://github.com/wp-graphql/wpgraphql-acf/issues/109
I'm going to close this in favor of tracking it in the new repo.