Title: get_posts now altering main loop
Last modified: August 22, 2016

---

# get_posts now altering main loop

 *  Resolved [angelamaria](https://wordpress.org/support/users/angelamaria/)
 * (@angelamaria)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/get_posts-now-altering-main-loop/)
 * I recently updated WordPress to 4.1.1 and get_posts is altering the main loop
   now.
 * See: [http://prayerforastrugglingartist.com/2014/11/30/levi-jun-miscala/](http://prayerforastrugglingartist.com/2014/11/30/levi-jun-miscala/)
 * I even moved my get_posts query out of the main template, but it’s definitely
   altering the main loop.
 * Code for the posts index on the left:
 *     ```
       <li><a href="<?php echo get_category_link(1); ?>">Testimonials</a>
           <ul>
               <?php
                   $posts = get_posts( 'category=1&orderby=title' );
                   foreach( $posts as $p ) {
                       ?> <li><a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo $p->post_title; ?></a></li> <?php
                   }
               ?>
           </ul>
   
       </li>
       ```
   
 * Is there any alternative I can use, since it looks like it’s broken for now?

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/get_posts-now-altering-main-loop/#post-5926554)
 * try to use a different variable name instead of `$posts` as this is also used
   in the main query;
 * and do add a `wp_reset_postdata()` after the end of the `foreach` loop.
 *  Thread Starter [angelamaria](https://wordpress.org/support/users/angelamaria/)
 * (@angelamaria)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/get_posts-now-altering-main-loop/#post-5926612)
 * Thank you! That worked amazing 🙂

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

The topic ‘get_posts now altering main loop’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [angelamaria](https://wordpress.org/support/users/angelamaria/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/get_posts-now-altering-main-loop/#post-5926612)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
