Skip to content

Commit b703ddf

Browse files
committed
feat: add files update mutation support
1 parent 32341f3 commit b703ddf

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.1",
2+
"version": "1.0.2",
33
"name": "zngly/wp-graphql-acf-mutations",
44
"description": "ACF Mutations for WP GraphQL",
55
"homepage": "https://github.com/zngly/wp-graphql-acf-mutations",

src/post_object.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace WPGraphQL\ACF\Mutations;
1010

1111
use WP_Post_Type;
12+
use WPGraphQL\Utils\Utils;
1213

1314
// add_action('graphql_post_object_mutation_update_additional_data', function ($post_id, $input, $mutation_name, $context, $info) {
1415
// if ($mutation_name->name === "my_post_type") {
@@ -114,10 +115,15 @@ protected function post_object_mutation_action($post_id, $input, WP_Post_Type $m
114115
continue;
115116
}
116117

117-
/**
118-
* update a standalone acf field
119-
*/
118+
// check if the field exists
120119
if (isset($input[$field['graphql_name']])) {
120+
// if file types are images or file, make sure an ID is passed
121+
if (in_array($field['type'], ['image', 'file']))
122+
$input[$field['graphql_name']] = Utils::get_database_id_from_id($input[$field['graphql_name']]);
123+
124+
/**
125+
* update a standalone acf field
126+
*/
121127
update_post_meta($post_id, $field['name'], $input[$field['graphql_name']]);
122128
}
123129
}

0 commit comments

Comments
 (0)