Title: Multiple loop working, function inside isn&#8217;t
Last modified: August 19, 2016

---

# Multiple loop working, function inside isn’t

 *  Resolved [bccarlso](https://wordpress.org/support/users/bccarlso/)
 * (@bccarlso)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/multiple-loop-working-function-inside-isnt/)
 * Hi all, I’m using this piece of code I found ([http://impnerd.com/wordpress-hack-add-post-images-to-your-homepage](http://impnerd.com/wordpress-hack-add-post-images-to-your-homepage))
   to display the first image uploaded to a post on the homepage next to the excerpts
   of posts. I’m doing this outside the main loop on the homepage, and have been
   having problems. When I do rewind_posts() to get the same loop results, it works
   fine, but when I try to create a different loop, this code snippet breaks down:
 *     ```
       <?php $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
       if ($images) {
       $keys = array_keys($images);
       $num = $keys[0];
       $firstImageSrc = wp_get_attachment_thumb_url($num);
       echo "<li><img src=\"{$firstImageSrc}\" width=\"288\" height=\"216\"  alt=\"\" title=\"\" /></li>";} ?>
       ```
   
 * I have tried the methods in The_Loop#Multiple_Loops_in_Action in the docs, and
   they work, meaning I can get normal output after the loop, but my snippet above
   doesn’t work. Any idea if there is a conflicting method call or something that’s
   going on that’s stopping it from working? Would appreciate some help, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [bccarlso](https://wordpress.org/support/users/bccarlso/)
 * (@bccarlso)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/multiple-loop-working-function-inside-isnt/#post-1266843)
 * To be more specific:
 *     ```
       <?php $my_query = new WP_Query('category_name=Daily Photo&showposts=1');
       while ($my_query->have_posts()) : $my_query->the_post();
       $do_not_duplicate = $post->ID; ?>
       <p>a</p>
       <?php $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
       if ($images) {
       $keys = array_keys($images);
       $num = $keys[0];
       $firstImageSrc = wp_get_attachment_thumb_url($num);
       echo "<li><img src=\"{$firstImageSrc}\" width=\"288\" height=\"216\"  alt=\"\" title=\"\" /></li>";} ?>
       <?php endwhile; ?>
       ```
   
 * will output `<p>a</p>`, but not the
    `<li><img /></li>` code I need in the snippet.
   Whereas if I use rewind_posts();, everything works, and I get the `<li><img /
   ></li>` code, but I don’t want to use the same loop that I had been using previously.
   I’m using this to display a daily photo in the sidebar, that pulls from the “
   Daily Photo” category. I will exclude Daily Photos from the main loop, and only
   want to use them to draw images from in that snippet.
 *  Thread Starter [bccarlso](https://wordpress.org/support/users/bccarlso/)
 * (@bccarlso)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/multiple-loop-working-function-inside-isnt/#post-1266849)
 * Figured it out, somehow the image got assigned to the Media Library and not the
   Gallery for the specific post I was using.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Multiple loop working, function inside isn’t’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [bccarlso](https://wordpress.org/support/users/bccarlso/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/multiple-loop-working-function-inside-isnt/#post-1266849)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
