Title: query posts BEFORE the main loop
Last modified: August 18, 2016

---

# query posts BEFORE the main loop

 *  Resolved [lobsterman](https://wordpress.org/support/users/lobsterman/)
 * (@lobsterman)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/)
 * I want to display a custom post on top of each page, the problem is, it will 
   reset the loop, so the main loop won’t show the right thing for that page. is
   there any way around it except putting the code itself under the main loop?

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

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366151)
 * Start of your custom post loop:
 * `<?php
    $custom = new WP_Query('your_args'); while($custom->have_posts()) : $
   custom->the_post();  ?>
 * When setting up a new query class through WP_Query(), note it accepts all the
   same arguments as [query_posts()](http://codex.wordpress.org/Template_Tags/query_posts).
 *  Thread Starter [lobsterman](https://wordpress.org/support/users/lobsterman/)
 * (@lobsterman)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366251)
 * Thanks allot, that’s exactly what I needed.
    Just one more thing, I remember 
   reading somewhere how to do this, but I cant remember where. how do I offset 
   the posts to start from the 3rd post?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366256)
 * You can’t. At least, not with query_posts() or by setting up a new WP_Query class.
   For an offset you’ll have to stick with using an older method:
 * [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 *  Thread Starter [lobsterman](https://wordpress.org/support/users/lobsterman/)
 * (@lobsterman)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366257)
 * This works great, Thanks!
    Just for general reference, what’s the difference 
   between this and query posts? this seems to be better for multiple loops, is 
   that true?
 *  [savorymedia](https://wordpress.org/support/users/savorymedia/)
 * (@savorymedia)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366258)
 * _“You can’t. At least, not with query\_posts() or by setting up a new WP\_Query
   class. For an offset you’ll have to stick with using an older method:_
 * [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)“
 * Actually, I DID use query_posts() with some more elements to get a list with 
   one main post and a list of more posts…with an offset.
 * Check the second code example [here](http://wordpress.org/support/topic/67290?replies=4).
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366259)
 * SavoryMedia, I’ll amend my previous claim and say it can’t be done _without some
   custom coding outside the function_. But I’m still technically right. `;)`
 * lobsterman, each has its limitations. get_posts certainly is beneficial with 
   its ‘offset’ param, whereas query_posts/WP_Query provides a broader mechanism
   and works off the standard post loop. Sort of a coin toss in many cases, though.
 *  Thread Starter [lobsterman](https://wordpress.org/support/users/lobsterman/)
 * (@lobsterman)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366265)
 * Thanks.

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

The topic ‘query posts BEFORE the main loop’ is closed to new replies.

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 7 replies
 * 3 participants
 * Last reply from: [lobsterman](https://wordpress.org/support/users/lobsterman/)
 * Last activity: [20 years, 2 months ago](https://wordpress.org/support/topic/query-posts-before-the-main-loop/#post-366265)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
