Skip to content

Instantly share code, notes, and snippets.

@MKlblangenois
Last active August 7, 2023 11:16
Show Gist options
  • Save MKlblangenois/799d07f9b838c2ea1662dbcc5b1091e3 to your computer and use it in GitHub Desktop.
Save MKlblangenois/799d07f9b838c2ea1662dbcc5b1091e3 to your computer and use it in GitHub Desktop.
Fix for WPGraphQL ACF Gutenberg: block null or duplicated content
// 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;
}
// 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