Title: Query within Query?
Last modified: August 19, 2016

---

# Query within Query?

 *  [John Robertson](https://wordpress.org/support/users/braddor/)
 * (@braddor)
 * [16 years ago](https://wordpress.org/support/topic/query-with-query/)
 * At the top of my site, just before the main loop, I have a query that pulls the
   posts from a certain category. Now I got that to work fine but I wanted to step
   it up a notch…
 * The section is designed so the big main div shows the latest post from a category,
   while inside that box a small section shows the other posts by date from the 
   same category, using an offset condition.
 * However that’s how I see it on paper, how do I integrate the two queries so one
   can work within the other.
 * Basically it would be:
 * <?php $my_query = new WP_Query(‘category_name=featured&showposts=1’); ?>
    <?php
   while ($my_query->have_posts()) : $my_query->the_post(); ?> [HTML showing one
   post]
 * ====== sub query =======
    <?php $my_query = new WP_Query(‘category_name=featured&
   showposts=3&offset=1’); ?> <?php while ($my_query->have_posts()) : $my_query-
   >the_post(); ?> [HTML sub stuff with 1 post offset] <?php endwhile; ?> ======
   sub query =======
 * <?php endwhile; ?>
 * Obviously wrapping a query within a query like what I did above doenst make sense…
   so how do I do it?

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years ago](https://wordpress.org/support/topic/query-with-query/#post-1502747)
 * ====== sub query =======
 *     ```
       <?php $my_query2 = new WP_Query('category_name=featured&showposts=3&offset=1'); ?>
       <?php while ($my_query2->have_posts()) : $my_query2->the_post(); ?>
       [HTML sub stuff with 1 post offset]
       <?php endwhile; ?>
       ```
   
 * ====== sub query =======

Viewing 1 replies (of 1 total)

The topic ‘Query within Query?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/query-with-query/#post-1502747)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
