WordPress.org

Forums

[resolved] [closed] How to retrieve multiple pages using query_posts? (10 posts)

  1. trex33
    Member
    Posted 5 years ago #

    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?

  2. MichaelH
    Member
    Posted 5 years ago #

    Try this:

    <?php
    $args = array(
      'post_type' => 'page',
      'post__in' => array(3,5,7)
      );
    query_posts($args);
    ?>
  3. trex33
    Member
    Posted 5 years ago #

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

  4. Jon Bishop
    Member
    Posted 5 years ago #

    I was looking for this everywhere. Thanks so much.

  5. SAMsan
    Member
    Posted 5 years ago #

    TU soooo much :D

  6. weboncloud
    Member
    Posted 5 years ago #

    Thank you so much..this was very helpful

  7. mitchrenton
    Member
    Posted 5 years ago #

    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?

  8. georgecampos
    Member
    Posted 5 years ago #

    Thank you so much :)

  9. justinbriggs1
    Member
    Posted 5 years ago #

    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?

  10. Cultivate
    Member
    Posted 4 years ago #

    mitchrenton

    add 'order' => 'asc

    like this

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

Topic Closed

This topic has been closed to new replies.

About this Topic