Support » Fixing WordPress » How to retrieve multiple pages using query_posts?

  • Resolved trex33

    (@trex33)


    According to codex, you can use query_posts to retrieve a specific page:

    <?php query_posts('page_id=7'); ?>

    So how do you retrieve multiple pages using query_posts? I tried this (which works fine when you retrieve posts for multiple categories):

    <?php query_posts('page_id=3,5,7'); ?>

    Unfortunately, this only retrieves page_id 3, not all of them. Any ideas?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Try this:

    <?php
    $args = array(
      'post_type' => 'page',
      'post__in' => array(3,5,7)
      );
    query_posts($args);
    ?>

    Perfect! Thanks as always Michael. I didn’t even know post__in existed.

    Jon Bishop

    (@jonbishop)

    I was looking for this everywhere. Thanks so much.

    SAMsan

    (@samsan)

    TU soooo much 😀

    Thank you so much..this was very helpful

    Just used this piece of code, thanks very much. I added an “orderby” into the array and for some reason none of them are working, meaning I’ve ordered by “ID”, “menu_order”, “modified” but none of them change the order of pages that I’m looking for.

    EG. ‘orderby’ => ‘menu_order’

    Am I missing something here?

    Thank you so much 🙂

    Thanks, I was looking for something very similar, but I would also like to select all of the pages, not just a few. How would I go about doing that?

    mitchrenton

    add 'order' => 'asc

    like this

    <?php $args = array('post_type' => 'page', 'order' => 'asc', 'post__in' => array(139, 141, 143)); query_posts($args); ?>

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to retrieve multiple pages using query_posts?’ is closed to new replies.