Results 1 to 5 of 5

Thread: get_pages() order

  1. #1
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default get_pages() order

    I'm clearly doing something totally daft as I can't get the following code to work:

    PHP Code:
    <?php


    $pages 
    get_pages'orderby=ID' );
    foreach (
    $pages as $pagg) {
        echo 
    $pagg->ID '|' .$pagg->post_title '<br />';
    }

    ?>
    That does not display page IDs/titles ordered by ID's when I use it in a theme.


    Any ideas on what on earth I'm doing wrong? This is driving me nuts!


    Thanks :)

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    ... continuing my stellar habit of finding the answer AFTER I give up in desperation and turn to to the Tavern for help ...

    get_pages() doesn't support orderby, only get_posts does, so the following does the trick:

    PHP Code:
    <?php


    $pages 
    get_posts'orderby=menu_order&post_type=page' );
    foreach (
    $pages as $pagg) {
        echo 
    $pagg->ID '|' .$pagg->post_title '<br />';
    }

    ?>

  3. #3
    Cais's Avatar
    Cais is offline Big Tipper
    Join Date
    Feb 2009
    Location
    Mississauga, ON, CANADA
    Posts
    349

    Default

    Did you try this:
    PHP Code:
    $pages get_pages'sort_column=ID' ); 
    foreach (
    $pages as $pagg) { 
        echo 
    $pagg->ID '|' .$pagg->post_title '<br />'


  4. #4
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    Oh, thanks, that works too. I wonder why they did get_pages() and get_posts() differently.

  5. #5
    sleary's Avatar
    sleary is offline Hello World
    Join Date
    Dec 2009
    Location
    Texas
    Posts
    21

    Default

    get_pages does support ordering, but the parameter is different. This should work as well:

    Code:
    get_pages('sort_order'=> 'ASC', 'sort_column' => 'ID');
    Last edited by sleary; 02-25-2010 at 12:07 PM. Reason: editor keeps inserting extra code tags, ARGH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •