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
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.