admin管理员组文章数量:1022935
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"
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"
本文标签: block editorGutenberg sidebar example does not update meta field in the database
版权声明:本文标题:block editor - Gutenberg sidebar example does not update meta field in the database 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745551422a2155648.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论