Title: Strange Loop Problem
Last modified: August 18, 2016

---

# Strange Loop Problem

 *  Resolved [faustina](https://wordpress.org/support/users/faustina/)
 * (@faustina)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/strange-loop-problem/)
 * [http://www.gollygolly.com/category/photos/](http://www.gollygolly.com/category/photos/)
 * Go there, you will see my problem. I really don’t know what’s causing this. This
   is the only code in the page of any substance:
 * `<?php if (! empty($display_stats) ) { get_stats(); } else if (($posts & empty(
   $display_stats)) ) : foreach ($posts as $post) : start_wp(); ?> 
    <div class="
   entrycat"> <?php $arc_query = new WP_Query('category_name=photos&orderby=post_date&
   order=DESC&showposts=-1'); ?> <?php while ($arc_query->have_posts()) : $arc_query-
   >the_post(); ?><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?
   >"><?php echo $post->post_excerpt; ?></a> <?php endwhile; ?>  </div>  <?php endforeach;
   else: ?>
 * Any ideas on what I need to change?

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

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/strange-loop-problem/#post-502637)
 * You have one posts loop (generated through WP_Query()) nested in another (`foreach(
   $posts as $post)`), and this is causing the displaying of each post multiple 
   times. 5 times 5, to be exact.
 * At this point I wouldn’t know what to suggest to replace the code above as I’ve
   no idea what is important and what isn’t. But you can try whittling it down to:
 * `<div class="entrycat">
    <?php $arc_query = new WP_Query('category_name=photos&
   orderby=post_date&order=DESC&showposts=-1'); ?> <?php while ($arc_query->have_posts()):
   $arc_query->the_post(); ?><a href="<?php the_permalink(); ?>" title="<?php the_title();?
   >"><?php echo $post->post_excerpt; ?></a> <?php endwhile; ?> </div>
 * And go from there.
 *  Thread Starter [faustina](https://wordpress.org/support/users/faustina/)
 * (@faustina)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/strange-loop-problem/#post-502659)
 * How would I close that? This is what I have tried putting after the code you 
   suggested:
 * `<?php endforeach; else: ?> 
    <div class="center"> <h2>Not Found</h2> </div> 
   <?php endif; ?>
 *  </div>
    <?php get_sidebar(); ?>
 * </div>
    <?php get_footer(); ?>
 * I get page errors for the ‘foreach’ statement, but I can’t seem to find anything
   that works.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/strange-loop-problem/#post-502734)
 * What I gave above is a complete statement or code block. You don’t close it with`
   endforeach` or `endif` because it’s a `while` statement, hence the `endwhile`
   at the end. But if you need a conditional, you can change it to:
 * `<?php if($arc_query->have_posts()) : while($arc_query->have_posts()) : $arc_query-
   >the_post(); ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title();?
   >"><?php echo $post->post_excerpt; ?></a> <?php endwhile; else : ?> <div class
   ="center"> <h2>Not Found</h2> </div> <?php endif; ?>
 *  Thread Starter [faustina](https://wordpress.org/support/users/faustina/)
 * (@faustina)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/strange-loop-problem/#post-502785)
 * I don’t really NEED the conditional, so I just ended it with the while. It worked
   perfectly. Thank you so much, I appreciate the help. I am pretty good with code
   but querys are completely strange to me. Thank you.
 *  Thread Starter [faustina](https://wordpress.org/support/users/faustina/)
 * (@faustina)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/strange-loop-problem/#post-503054)
 * If you, or anyone could take a look – [http://www.gollygolly.com/category/photos/](http://www.gollygolly.com/category/photos/)–
   That is the page where I am using this code. In IE the photos (excerpts) don’t
   show up! It’s funny because the source code says that they are there, but nothing
   is there to see. Any ideas?

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

The topic ‘Strange Loop Problem’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [faustina](https://wordpress.org/support/users/faustina/)
 * Last activity: [19 years, 4 months ago](https://wordpress.org/support/topic/strange-loop-problem/#post-503054)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
