0

I am using meta boxes from WP tuts this tutorial http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-3-extra-fields/ everything works fine but I don't know ho to call value from image uploader. In my index.php I used this code

<?php $image_upload = get_post_meta($post->ID, $field['custom_image'], true);?>
<?php print_r($image_upload );?>

and it printed this

Array ( 
    [_edit_last] => Array ( [0] => 1 ) 
    [_edit_lock] => Array ( [0] => 1331586724:1 ) 
    [_thumbnail_id] => Array ( [0] => 152 ) 
)

And when I write this code:

<?php echo wp_get_attachment_image(152); ?>

It shows completly diferent image. Does someone know what I am doing wrong?

1 Answer 1

1

It appears that $field['custom_image'] isn't passing what you want it to. The returned values do not appear to be correct.

You want to put the key of the meta value you need as the second variable in the get_post_meta() function, for example:

$image_upload = get_post_meta($post->ID, '_my_image_id', true);

Each custom meta field you create has a unique identifier, thats the value you want to pass in.

You should also check to see if the returned value of $image_upload is false, in which case the meta was not set for that particular post.

1
  • So I solved the problem myself :D I was so stupid :D I forgot to put this code in the loop :D :D <?php $image_upload_id = get_post_meta($post->ID, $field['custom_image'], true);?> <?php $img = $image_upload_id ['custom_image'][0];?> and than just put <?php echo wp_get_attachment_image($img); ?> I am sorry for my stupid fault and question :D
    – Itachi
    Commented Mar 19, 2012 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.