Title: query_posts() twice?
Last modified: August 18, 2016

---

# query_posts() twice?

 *  Resolved [crazydrumguy](https://wordpress.org/support/users/crazydrumguy/)
 * (@crazydrumguy)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/)
 * I am using query_posts() on my site to display the most recent post in a box 
   on the side of the page. Is there any way I can use query_posts() a second time
   to display something else in the main content area? (See [crazydrumguy.info](http://crazydrumguy.info)
   for an example.) The message on the green background is static, but I’d like 
   to have it pull from another category in the blog. Can I use query_posts() twice
   in the same Loop? Can I create two Loops on one page?

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

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/#post-373388)
 * You cannot use query_posts() more than once on a particular post loop, but you
   can set up (and initialize with query_posts()) as many loops as you like.
 *  Thread Starter [crazydrumguy](https://wordpress.org/support/users/crazydrumguy/)
 * (@crazydrumguy)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/#post-373390)
 * Thanks! I currently have the call to query_posts() at the very top of my page(
   immediately under get_header()). Is there a certain place where I should place
   it for it to work with both loops? Can it go within the loop itself?
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/#post-373392)
 * “_Can it go within the loop itself?_“
 * No. It needs to go before it.
 * Each time you need a new loop you have to set up another one, meaning another
   loop, in the location you want it. A very basic (and non-working) example would
   be:
 * `<?php query_posts('FIRST QUERY ARGS'); ?>
    <?php while(have_posts()) : the_post();?
   > <?php the_title(); ?> <?php the_content(); ?> <?php endwhile; ?>
 * `<?php query_posts('SECOND QUERY ARGS'); ?>
    <?php while(have_posts()) : the_post();?
   > <?php the_title(); ?> <?php the_content(); ?> <?php endwhile; ?>
 * And so on for each loop.
 *  Thread Starter [crazydrumguy](https://wordpress.org/support/users/crazydrumguy/)
 * (@crazydrumguy)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/#post-373393)
 * Thanks for your help. The query_posts() codex entry really needs some work…. 
   😉
 *  [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/#post-373415)
 * I prefer to just do it manually:
 * `$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE [stuff here]");`

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

The topic ‘query_posts() twice?’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)
 * [templates](https://wordpress.org/support/topic-tag/templates/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * Last activity: [20 years, 1 month ago](https://wordpress.org/support/topic/query_posts-twice/#post-373415)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
