Title: get_posts() displaying multiple times in loop
Last modified: August 19, 2016

---

# get_posts() displaying multiple times in loop

 *  Resolved [ramijames](https://wordpress.org/support/users/ramijames/)
 * (@ramijames)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/get_posts-displaying-multiple-times-in-loop/)
 * Hi Guys and Gals,
 * I’ve been using wordpress as a CMS for a site that I’m developing.
 * I’ve hit a bit of a snag. I’m creating a custom archive page which I want to 
   show only the header and an excerpt from each available ‘post’. This is going
   to show as a list of press releases. I’ve gotten everything working as I like..
   but the posts show up three times instead of one. I mean something like this:
 * Post 1
    Post 2 Post 3 Post 4 Post 1 Post 2 Post 3 Post 4 Post 1 Post 2 Post 3
   Post 4
 * Which is obviously not good.
 * The code I’m using to generate the list is:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
         <div class="archives">
           <ul>
       							       <?php
       global $post;
       $myposts = get_posts('offset=0');
       foreach($myposts as $post) :
       setup_postdata($post);
       ?>
       <li>
       <a href="<?php the_permalink(); ?>"><h2><?php the_title();?></h2></a>
       									<?php the_excerpt(); ?>
               </li>
             <?php endforeach; ?>
           </ul>
         </div>
       <?php endwhile; else: ?>
   
       <p>Sorry, no posts matched your criteria.</p>
   
       <?php endif; ?>
       ```
   
 * It’s from the wp manual and I’m sure that I’ve messed up somewhere.
 * Any help would be greatly appreciated.

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

 *  Thread Starter [ramijames](https://wordpress.org/support/users/ramijames/)
 * (@ramijames)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/get_posts-displaying-multiple-times-in-loop/#post-665349)
 * I’ve found a solution which is much simpler.
 *     ```
       <?php query_posts('showposts=10000'); ?>
                                <div class="archives">
                                    <ul>
                                     <?php while (have_posts()) : the_post(); ?>
                                       <li>
                                       	<a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
                                       	<?php the_excerpt(); ?>
                                       </li>
                                     <?php endwhile; ?>
                                    </ul>
                                </div>
       ```
   
 * I’m not really sure what the difference is, honestly.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/get_posts-displaying-multiple-times-in-loop/#post-665359)
 * Your first example has two [Loops](http://codex.wordpress.org/The_Loop).
 * See also, [The Loop in Action](http://codex.wordpress.org/The_Loop_in_Action)
 *  Thread Starter [ramijames](https://wordpress.org/support/users/ramijames/)
 * (@ramijames)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/get_posts-displaying-multiple-times-in-loop/#post-665432)
 * Yes, I noticed that after studying it for a while.
 * Thanks for the help.

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

The topic ‘get_posts() displaying multiple times in loop’ is closed to new replies.

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [ramijames](https://wordpress.org/support/users/ramijames/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/get_posts-displaying-multiple-times-in-loop/#post-665432)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
