Error on above code… Use this:
$custom_meta = get_post_custom($post->ID);
$background = unserialize($custom_meta['background'][0]);
Works.
But i think you can just call something like this:
$background = get_post_meta($post->ID, 'background', true);
Using get_post_meta insted of get_post_custom.
Being “background” the ID you put into you metaboxex.php for that particular option.
And you will have the same data.
Can be unserialized if you want too, or treated like whatever you want.
oh, thank you, would this work for images? or would I need the wp_get_attachment_image_src()? code
Is that code above mainly for the list-item option type or does it work on others? not in list-items?
Ok I have the following:
function custom_meta_boxes() {
$my_meta_box = array(
'id' => 'my_meta_box',
'title' => 'Images on Right Column',
'desc' => '',
'pages' => array( 'page' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'id' => 'firstimg',
'label' => 'First img',
'desc' => 'Add images here to appear on right column',
'std' => '',
'type' => 'upload',
'class' => 'fimg'
),
array(
'label' => 'second Upload',
'id' => 'imgs_sec',
'type' => 'upload',
'desc' => 'Second Right Col Image',
'class' => 'simg'
),
array(
'label' => 'Third Upload',
'id' => 'imgs_th',
'type' => 'upload',
'desc' => 'Third Right Col Image',
'class' => 'timg'
),
)
);
ot_register_meta_box( $my_meta_box );
and I’m hoping to call back the images I uploaded, so I edited your code and did this:
<?php //images
$custom_meta = get_post_custom($post->ID);
$background = unserialize($custom_meta['my_meta_box'][0]);
$backimg = $background['firstimg'];
echo wp_get_attachment_image_src($backimg , "full");
?>
And I have no luck at getting any images. 🙁
I’m sort of confused about which variables go where, as you may see in my code above
I’m not sure but I’ll try to test your code. I assume you are trying to get the URL of the full size of the uploaded image?
Well, I’m trying to get the image to show up, period. So I guess I left out the img src code.
Can you please try my code? It’s driving me crazy 🙁
Try this in place of what you have:
$background = unserialize($custom[‘firstimg’]);
Then just echo $background to see if it’s got data.
My example was for a background. You might need
$background = unserialize($custom[‘firstimg’][0]);
You can also use print_r($background) to see the array and then use the appropriate field such as [‘background-image’] or whatever…
Try that and let me know…. Should work.
Hi,
I’d like to know the reason to use unserialize function in my code.