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'm using Gravity Forms to create a form. The form entry is created as a post. I have a loop that successfully gets the content of the post.

However, I'd also like to get the image that is submitted with the post. I have this snippet:

<?php wp_get_attachment_link($POST->ID) ; ?>

However, this makes returns nothing. This makes me think that either the code is incorrect, or that GF is storing the image in a way that differs from how normal post images are stored.

This is my full loop:

<?php global $query_string ; ?>
  <?php  $my_query = new WP_Query('&cat=4&posts_per_page=10') ?>
  <?php  while ( $my_query->have_posts())  : $my_query->the_post() ; ?>
   <img src="<?php wp_get_attachment_link() ; ?> " class="" alt="#" />
      <a href="<?php the_permalink() ?>"  title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
      <?php the_content() ;?>

How can I get the image?

share|improve this question
By default, wp_get_attachment_link() returns either a link to an image or Missing Attachment - have you tried to do die( var_dump( wp_get_attachment_link( $post->ID ) ) ); to see what's returned? – Jared Jan 22 '12 at 15:50

You can use this to identify the attachments in a post:

$args = array(
    'post_type' => 'attachment',
    'post_parent' => $post->ID
$images = get_posts($args);
foreach($images as $image){
   echo wp_get_attachment_image($image->ID, 'size')
share|improve this answer

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.