WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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
share|improve this answer
That has in fact worked a treat, thank you very much! – Adam Moss Aug 7 '12 at 16:16
No worries. I was just stabbing in the dark, haha. Don't forget to mark answered ;) – RCNeil Aug 7 '12 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 '12 at 16:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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