Leave a Reply

4 comments

  1. To show post type meta data on a single page template, I assume that you’re in the Loop.

    // Use get_the_ID() to get the ID via the API function
    echo get_post_meta( get_the_ID(), 'my-info', true );
    // You can also call it from the global, as the query refers to the current single page
    echo get_post_meta( $GLOBALS['post']->ID, 'my-info', true );
    

    If you’re not getting any output, then you might want to check your complete set of post custom data:

    printf( '<pre>%s</pre>', var_export( get_post_custom( get_the_ID() ), true ) );
    
  2. Use IDs of fields to get meta data of respective fields as following code.

    global $post;
    $meta = get_post_meta($post->ID,'myinfo-box1', true); // Use myinfo-box1, myinfo-box2, myinfo-box3 for respective fields
    if ($meta != '') {
        echo $meta;
    } else { 
        echo "Can't Display The Content";
    } 
    
  3. Some times id is not working then we can use name attribute.

    For displaying meta box values your code must be in loop.

    $meta = get_post_meta($post->ID,'meta-box-text', true);
    

    Here meta-box-text is name attribute of my input text field.

    It works perfect for me.