Hello,
Yes, that’s a good idea. I’m not a fan of this solution as it’s not “field based”, but it will work in your case. Here is a code example:
add_action('acf/save_post', 'my_acf_blocks_save');
function my_acf_blocks_save($post_id){
// Bail early if not a Post
if(!is_numeric($post_id))
return;
// Parse Blocks
$blocks = parse_blocks(get_the_content($post_id));
/*
* Array(
* [0] => Array(
* [blockName] => acf/my-block-type
*
* [attrs] => Array(
* [id] => block_5f3575c1bcbff
* [name] => acf/my-block-type
* [data] => Array(
* [image] => 189
* [_image] => field_5f35759ff724d
* )
* [mode] => preview
* )
*
* [innerBlocks] => Array()
* [innerHTML] =>
* [innerContent] => Array()
* )
* )
*/
$thumbnail_id = false;
foreach($blocks as $block){
// Target specific ACF Block Type
if($block['blockName'] !== 'acf/my-block-type')
continue;
// Check the field
if(!isset($block['attrs']['data']['image']) || empty($block['attrs']['data']['image']))
continue;
// Retrieve Thumbnail ID
$thumbnail_id = $block['attrs']['data']['image'];
// Stop foreach
break;
}
// Set Post Thumbnail ID
update_post_meta($post_id, '_thumbnail_id', $thumbnail_id);
}
I’ll look for a more elegant solution (field based, instead of being based on page save) for ACF Extended in the future.
Concerning your question about metabox placement, unfortunately Gutenberg doesn’t allow it. Maybe this will come in a future ACF update.
Hope it helps!
Regards.