I have the following block and it works well when adding it multiple times to a post. However, when I go back to edit the post, the select2 only works for one instance of the block and the other select items use a standard select. Is this a bug or do I have something setup wrong? For now I can workaround by using context => side and a render template and removing mode => edit, but I would prefer for this to use mode => edit.
// Register a block for Gutenberg
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
$meta_boxes[] = [
'title' => 'VIEW Post Picker',
'id' => 'view-post-picker',
'type' => 'block', // Important.
'icon' => 'admin-post', // Or you can set a custom SVG if you don't like Dashicons
'category' => 'text',
//'context' => 'side', // The block settings will be available on the right sidebar.
'mode' => 'edit', //The default mode of the block: edit to make it shows the edit fields when loaded, preview (default) to show the rendered HTML when loaded.
//'render_template' => get_stylesheet_directory() . '/blocks/hero/template.php', // The PHP template that renders the block.
//'enqueue_style' => get_stylesheet_directory_uri() . '/blocks/hero/style.css', // CSS file for the block.
// Now register the block fields.
'fields' => [
[
'id' => 'vpp_post',
'type' => 'post',
'name' => 'Post or Page?',
'post_type' => ['post','page'],
'field_type' => 'select_advanced',
],
[
'id' => 'vpp_attachment',
'type' => 'post',
'name' => 'Attachment?',
'post_type' => 'attachment',
'field_type' => 'select_advanced',
'query_args' => [
'post_status' => ['publish','inherit'],
'posts_per_page' => - 1,
],
],
],
];
return $meta_boxes;
});