Title: Sidebar loop overwrites main loop
Last modified: August 19, 2016

---

# Sidebar loop overwrites main loop

 *  Resolved [BK_@_UC](https://wordpress.org/support/users/bk_uc/)
 * (@bk_uc)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/sidebar-loop-overwrites-main-loop/)
 * When you use multiple loops – like a custom loop in your side bar, it may overwrite
   your main loop… After troubleshooting where the problem was occurring and trying
   rewind_loop() unsuccessfully I found that starting a new loop would do the trick…
 *     ```
       while (have_posts()) : the_post();
          //the_content() was getting overwritten when by itself
          //but when enclosed with the while() statement
          //it works properly
          the_content();
       endwhile;
       ```
   
 * This works, but Im not sure if this is best practice, if you have any follow 
   up suggestions feel free to post…

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/sidebar-loop-overwrites-main-loop/#post-1986913)
 * [http://codex.wordpress.org/Function_Reference/get_post](http://codex.wordpress.org/Function_Reference/get_post)
   
   [http://codex.wordpress.org/Function_Reference/WP_Query](http://codex.wordpress.org/Function_Reference/WP_Query)
   [http://codex.wordpress.org/Function_Reference/wp_reset_query](http://codex.wordpress.org/Function_Reference/wp_reset_query)
 *  Thread Starter [BK_@_UC](https://wordpress.org/support/users/bk_uc/)
 * (@bk_uc)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/sidebar-loop-overwrites-main-loop/#post-1987123)
 * Great… wp_reset_query was the answer! Thanks much…
 * [http://codex.wordpress.org/Function_Reference/wp_reset_query](http://codex.wordpress.org/Function_Reference/wp_reset_query)
 * `<?php wp_reset_query(); ?>`
 * or
 *     ```
       <?php
       query_posts('posts_per_page=5');
       if (have_posts()) : while (have_posts()) : the_post();
       	?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><br /><?php
       endwhile; endif;
       wp_reset_query();
       ?>
       ```
   

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

The topic ‘Sidebar loop overwrites main loop’ is closed to new replies.

## Tags

 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [overwrite](https://wordpress.org/support/topic-tag/overwrite/)
 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [BK_@_UC](https://wordpress.org/support/users/bk_uc/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/sidebar-loop-overwrites-main-loop/#post-1987123)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
