Support Forum
I have read and repeatedly tried to implement the code on this page to display fields:
https://docs.metabox.io/displaying-fields/
but it just isn't working.
Here is the code from metabox for creating my metabox:
function coaching_lesson_meta_box( $meta_boxes ) {
$prefix = 'prefix-';
$meta_boxes[] = array(
'id' => 'coaching_lessons-metabox',
'title' => esc_html__( 'Coaching Lesson Components', 'metabox-online-generator' ),
'post_types' => array('post', 'page', 'coaching_program', 'coaching_lesson' ),
'context' => 'after_title',
'priority' => 'default',
'autosave' => 'false',
'fields' => array(
array(
'id' => $prefix . 'coaching_lesson_summary',
'type' => 'textarea',
'name' => esc_html__( 'Summary of Coaching Lesson', 'metabox-online-generator' ),
),
This is the code on my single-coaching_lesson.php page:
<?php astra_entry_before(); ?>
<article itemtype="https://schema.org/CreativeWork" itemscope="itemscope" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php astra_entry_top(); ?>
<?php astra_entry_content_single();
?>
<?php
$value = rwmb_meta( 'coaching_lesson_summary' );
echo $value;
?>
It just isn't showing on the page.
What am I doing wrong?
Thank you very much
Sean
Hi Sean,
You're using field ID coaching_lesson_summary
in the helper function. But the real ID is $prefix . 'coaching_lesson_summary'
, which is prefix-coaching_lesson_summary
. So, your code should be:
$value = rwmb_meta( 'prefix-coaching_lesson_summary' );
echo $value;
Thank you very much, that worked perfectly! (of course!))
Sean
A followup question, please
that codes works great to display the value if something has been input into the metabox.
But if nothing is entered in the metabox, then it stills returns the word "array"
How can I fix this?
Thanks!
Sean
Hi Sean, I've just re-tested and don't see that problem. Is that the same code as above?