2

I am trying to echo the image src of an image I have uploaded for my custom post type outside of the while loop.

I have used the following:

$custom_fields = get_post_custom($_GET['id']);

I can easily now use this code to get, for example the phone number:

echo $custom_fields['telephone'][0]; // e.g. returns 0800 555 222 

However, when I try to get an image using the same code, all I get back is a number.

echo $custom_fields['logo'][0]; // e.g. returns 247

Doing a var_dump of $custom_fields, it seems as though I cannot load this data outside the loop using this function. Does anybody know what I'm supposed to do here without having to do a loop?

1 Answer 1

5

I believe you can get away with

$image_upload = get_post_meta($post->ID, 'logo', true); // CALL IMAGE

and then display it with

echo wp_get_attachment_image($image_upload);  // Echo image
3
  • That has in fact worked a treat, thank you very much!
    – Adam Moss
    Aug 7, 2012 at 16:16
  • No worries. I was just stabbing in the dark, haha. Don't forget to mark answered ;)
    – RCNeil
    Aug 7, 2012 at 16:17
  • I see now that the number returned is by get_post_meta and get_post_custom is an attachment ID, which just gets loaded into wp_get_attachment_image.
    – Adam Moss
    Aug 7, 2012 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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