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?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742316717a4420981.html
评论列表(0条)