Title: Query_posts   header = headache
Last modified: August 19, 2016

---

# Query_posts header = headache

 *  Resolved [crimsonjack](https://wordpress.org/support/users/crimsonjack/)
 * (@crimsonjack)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/using-query_posts-in-header/)
 * I’m trying to use query_posts to show a list of recent additions in the _header_.
   I got this working fine, except for one major issue. For some reason, after listing
   the 4 most recent articles, everypage lists these 4 articles.. So I’m guessing
   that somehow the Query_posts in the header is effecting the content of the whole
   page.
 * Is there a way to stop this?
    Does the content / entry loop have to be before
   any query_posts? (like how the sidebar is setup?)
 * [http://desunoto.com/otaku/](http://desunoto.com/otaku/)
 * This is what I’m using in my header.
 *     ```
       <?php query_posts('showposts=4');?>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
   
       <div class="contents">
       <strong><a title="View this post" href="<?php the_permalink() ?>">
       <?php the_title() ?>
       </a></strong>
       </div>
   
       <?php endwhile; endif; ?>
       ```
   

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

 *  [ivovic](https://wordpress.org/support/users/ivovic/)
 * (@ivovic)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/using-query_posts-in-header/#post-762726)
 * there’s a default query in place for each “view”… when you run the query in the
   header, you intercept that before the page template can get its hands on the 
   default query.
 * the solution is to use a custom query variable which you’ll find under “multiple
   loops” on the query_posts codex page – or to use something like get_posts which
   is actually a lighter way to go anyway.
 *  Thread Starter [crimsonjack](https://wordpress.org/support/users/crimsonjack/)
 * (@crimsonjack)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/using-query_posts-in-header/#post-762733)
 * Thanks for pointing me in the right direction.
    I’ll give it a shot.
 * Also found [this](http://wordpress.org/support/topic/173957?replies=7) post from
   someone with the same problem.
 *  Thread Starter [crimsonjack](https://wordpress.org/support/users/crimsonjack/)
 * (@crimsonjack)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/using-query_posts-in-header/#post-762754)
 * I’m still having trouble with this.
 * What code should i use for the archive?
    have tried multiple things with no luck.
 *  Thread Starter [crimsonjack](https://wordpress.org/support/users/crimsonjack/)
 * (@crimsonjack)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/using-query_posts-in-header/#post-762757)
 * Ahh, there it goes.
 * Thanks again.

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

The topic ‘Query_posts header = headache’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [crimsonjack](https://wordpress.org/support/users/crimsonjack/)
 * Last activity: [18 years, 1 month ago](https://wordpress.org/support/topic/using-query_posts-in-header/#post-762757)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
