Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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() ; ?>
  <ul>
    <li>
   <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() ;?>
    </li>
  </ul>

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.