I am building a website using Wordpress in where I want to show the Metadata from the custom fields. I have setup the cmb2 in my function.php as like below the codes..
add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
function cmb2_sample_metaboxes() {
$cmb = new_cmb2_box( array(
'id' => 'test_metabox',
'title' => __( 'Test Metabox', 'cmb2' ),
'object_types' => array( 'page', ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
) );
$cmb->add_field( array(
'name' => __( 'Test Text', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'yourprefix_text',
'type' => 'text',
'show_on_cb' => 'cmb2_hide_if_no_cats',
) );
}
Ok, that is working in the post section, That's working. But when I tried to show Metadata in the front-end using
<?php
$text = get_post_meta( get_the_ID(), '_yourprefix_text', true );
echo esc_html( $text );
?>
nothing is echoing.
Anyone please find out what the problems are.