Last active
August 7, 2023 11:16
-
-
Save MKlblangenois/799d07f9b838c2ea1662dbcc5b1091e3 to your computer and use it in GitHub Desktop.
Fix for WPGraphQL ACF Gutenberg: block null or duplicated content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this filter inside your function.php | |
add_filter('acf/pre_save_block', 'add_acf_block_identifier'); | |
function add_acf_block_identifier($attributes) { | |
if (empty($attributes['id'])) { | |
$attributes['id'] = 'acf-block-' . uniqid(); | |
} | |
return $attributes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wp-graphql-gutenberg-acf/plugin.php:86 | |
// We need to replace `$root['attribute']['id']` by `$inner_id` inside plugin | |
$inner_id = $root['postId']; | |
if (array_key_exists('id', $root['attributes'])) { | |
$inner_id = $root['attributes']['id']; | |
} | |
acf_setup_meta( | |
$root['attributes']['data'], | |
$inner_id, | |
false | |
); | |
return $inner_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment