$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>metabox - How to get meta box data to display on a page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

metabox - How to get meta box data to display on a page

matteradmin10PV0评论

I am trying to piece together a Metabox with 3 text editor fields for a custom post type.

The box is showing up and appears to be saving on the custom post type entries but I can't get the data to display on the single-[custom-post-type].php page.

Most recently I have tried the following to get the meta box data to display on the page:

global $post;
$meta = get_post_meta($post->ID, 'my-info', true ); 
if ($meta != '') {
    echo $meta
} else { 
    echo "Can't Display The Content";
}

I'm not sure if it's a problem with my Metabox creation/save that I can't get it to display. If anyone can point me in the right direction I'd appreciate it.

Here is a link to the code that I'm using for my Metabox if it helps:

Metabox Code

I am trying to piece together a Metabox with 3 text editor fields for a custom post type.

The box is showing up and appears to be saving on the custom post type entries but I can't get the data to display on the single-[custom-post-type].php page.

Most recently I have tried the following to get the meta box data to display on the page:

global $post;
$meta = get_post_meta($post->ID, 'my-info', true ); 
if ($meta != '') {
    echo $meta
} else { 
    echo "Can't Display The Content";
}

I'm not sure if it's a problem with my Metabox creation/save that I can't get it to display. If anyone can point me in the right direction I'd appreciate it.

Here is a link to the code that I'm using for my Metabox if it helps:

Metabox Code

Share Improve this question edited Jun 16, 2018 at 8:33 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Mar 5, 2013 at 10:43 SyrehnSyrehn 3122 gold badges3 silver badges11 bronze badges 1
  • Any progress on that question? – kaiser Commented Oct 22, 2013 at 10:30
Add a comment  | 

4 Answers 4

Reset to default 8

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 ) );

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";
} 
$m_meta_description = get_post_meta($post->ID, 'images_url',true);

echo 'meta box value: ' . $m_meta_description;

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.

Post a comment

comment list (0)

  1. No comments so far