Custom Fields
Re-Envisioned
Support General I cannot get custom fields to display, thanks

This topic contains 4 replies, has 2 voices, and was last updated by  Anh Tran 6 months, 3 weeks ago.

  • Creator
    Topic
  • #13818
    Resolved
    Sean Mize
    Participant

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #13854

    Anh Tran
    Keymaster

    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;
    #13870

    Sean Mize
    Participant

    Thank you very much, that worked perfectly! (of course!))

    Sean

    #13873

    Sean Mize
    Participant

    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

    #13880

    Anh Tran
    Keymaster

    Hi Sean, I’ve just re-tested and don’t see that problem. Is that the same code as above?

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.