Versions
ACF – 5.8.2
WordPress – 5.2.1
Problem
Custom blocks with ACF fields cannot be correctly saved when placed after a core/image
block (even if several other core blocks are placed in-between.
Behavior identified:
The first of our ACF custom block that follows any core/image
block is having issues converting its ACF fields IDs to the corresponding aliases. As long as it was previously saved, everything is fine, but as soon as we update any value in the custom block while the image is before, then the values are not saved correctly.
Test case
twentynineteen/functions.php
:
function register_acf_block_types() {
// register a testimonial block.
acf_register_block_type(array(
"name" => "testimonial",
"title" => __("Testimonial"),
"description" => __("A custom testimonial block."),
"render_template" => "template-parts/block-testimonial.php",
"category" => "formatting",
"icon" => "admin-comments",
"keywords" => array( "testimonial", "quote" ),
));
}
// Check if function exists and hook into setup.
if( function_exists("acf_register_block_type") ) {
add_action("acf/init", "register_acf_block_types");
}
twentynineteen/template-parts/block-testimonial.php
:
<?php
$separator = "<br/>----------<br/>";
echo "<b>" . $block["name"] . "</b>";
echo $separator;
echo $block["data"]["title"];
echo $separator;
echo $block["data"]["_title"];
echo $separator;
No specific error has been thrown in the javascript console during the tests, and all http calsl to the WP Ajax admin have been successful. Tested on chrome / Edge and Windows / MacOS
The data format that should be recieved after saving and refreshing:
What is recieved:
This data has the exact same format as what the block receives while editing the custom blocks in Gutenberg and switching between edit mode and view mode. Normally, when saving and reloading, these values are translated to the aliases of our ACFs, as shown in the first screenshot, but in this particular situation, it is not the case.
Video demo
The topic ‘Gutenberg Image impedes ACF block data saving’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.