function register_video_post_type(): void {
$args = array(
'label' => __( 'Videos', 'video-features' ),
'description' => __( 'Videos catalogue', 'video-features' ),
'supports' => array(
'title',
'editor',
'author',
'thumbnail',
'revisions',
'custom-fields',
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'menu_icon' => 'dashicons-format-video',
);
register_post_type( 'video', $args );
register_post_meta(
'video',
'director',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => '[Director here]',
)
);
register_post_meta(
'video',
'genre',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => '[Genre here]',
)
);
register_post_meta(
'video',
'length',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => '[Length here]',
)
);
register_post_meta(
'video',
'trailer_url',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
'revisions_enabled' => true,
)
);
}
add_action( 'init', 'register_video_post_type' );
Description
When metadata is created via blocks bound to custom attributes, the metadata persists after the block is removed. This can result in unexpected behavior, such as that metadata continuing to erroneously render in a template.
This discussion also touches on overall Block Bindings UX, and may have implications for how we model content with bindings in the post editor, and potentially the site editor.
Step-by-step reproduction instructions
1. Register some custom post meta. For an easy example, here's code to register a custom post type with related meta:
Screenshots, screen recording, code snippet
removing-metadata.mp4
Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.