WordPress.org

Ready to get started?Download WordPress

Forums

Query within Query? (2 posts)

  1. John Robertson
    Member
    Posted 3 years ago #

    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?

  2. MichaelH
    Member
    Posted 3 years ago #

    ====== 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 =======

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.