Gutenberg example for creating sidebar / does not keep what is entered in the box. After refreshing the page, entered content is gone end text box is empty. I guess it is some kind of REST problem?
I just checked, when updating post, meta field is sent via POST request, therefore it is not a REST problem:
{"meta":{"sidebar_plugin_meta_block_field":"Jozica1"},"content":" ... etc
PHP Code:
add_action( 'init', function () {
if (is_admin()) {
wp_register_script( 'gmk-sidebar-js', get_template_directory_uri() . '/js/sidebar-panel.js',
[ 'wp-plugins', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data' ]
);
wp_register_style( 'gmk-sidebar-style', get_template_directory_uri() . '/css/admin-guten-sidebar.css' );
register_post_meta( '', 'sidebar_plugin_meta_block_field', array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
) );
}
} );
Gutenberg example for creating sidebar https://wordpress/gutenberg/handbook/designers-developers/developers/tutorials/plugin-sidebar-0/ does not keep what is entered in the box. After refreshing the page, entered content is gone end text box is empty. I guess it is some kind of REST problem?
I just checked, when updating post, meta field is sent via POST request, therefore it is not a REST problem:
{"meta":{"sidebar_plugin_meta_block_field":"Jozica1"},"content":" ... etc
PHP Code:
add_action( 'init', function () {
if (is_admin()) {
wp_register_script( 'gmk-sidebar-js', get_template_directory_uri() . '/js/sidebar-panel.js',
[ 'wp-plugins', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data' ]
);
wp_register_style( 'gmk-sidebar-style', get_template_directory_uri() . '/css/admin-guten-sidebar.css' );
register_post_meta( '', 'sidebar_plugin_meta_block_field', array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
) );
}
} );
Share
Improve this question
edited Apr 25, 2019 at 20:45
Lovor
asked Apr 24, 2019 at 21:04
LovorLovor
1,00610 silver badges16 bronze badges
2
- Please don't add the answer in your question please add a proper answer below. – norman.lol Commented Apr 25, 2019 at 20:18
- Possible duplicate of wordpress.stackexchange/q/329760/30597 – norman.lol Commented Apr 25, 2019 at 20:20
1 Answer
Reset to default 2Registration of meta field must happen outside of admin area check. I had it enclosed in if (is_admin)
check, so it was only happening when it passed this test. This was incorrect.
The question is duplicate and original question and answer are here: Plugin Sidebar is not Saving Meta Attribute to Post/Page after "Update"