admin管理员组文章数量:1332881
I registered boolean
by register_meta()
, to use it in my Gutenberg Plugin Sidebar,
I added default value to it true
:
register_meta( 'post', '_thefuturmeta_post_title_visibility', array(
'show_in_rest' => [
'schema' => [
'type' => 'boolean',
'default' => true,
]
],
'type' => 'boolean',
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
'auth_callback' => function() {
return current_user_can( 'edit_posts' );
}
) );
So after registering I can see its value in my console, then by my Gutenberg Sidebar I added ToggleControl
and can change this value, and everything's working perfect.
But I can't get my value properly in my theme:
$visibility_title = get_post_meta( get_the_ID(), '_thefuturmeta_post_title_visibility', true );
var_dump($visibility_title);
var_dump()
will always show boolean(true)
, if I change default value in get_post_meta to false
like this:
$visibility_title = get_post_meta( get_the_ID(), '_thefuturmeta_post_title_visibility', false );
I will get bool(false)
even if in my sidebar plugin I have true, but If I switch in my sidebar plugin to false and save and again switch to true, after this $visibility_title
will be showing always right values depending on ToggleControl
.
What am I doing wrong? I'm sure I have problem exactly here:
$visibility_title = get_post_meta( get_the_ID(), '_thefuturmeta_post_title_visibility', true );
But I can't understand what's wrong.
Can you help me, please?
本文标签: plugin developmentHow to get boolean value from registermeta properly
版权声明:本文标题:plugin development - How to get boolean value from register_meta properly? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742316706a2451958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论