Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress – Pages displaying out of order

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36198
    noahgelman
    Participant

    I’m listing out all my wordpress pages and a little bit of their content using a foreach loop like the following:

    
    $allPageIDs = get_all_page_ids();
    foreach($allPageIDs as $pageID) {
    $page_data = get_page( $pageID );
    $content = apply_filters('the_content', $page_data->post_content);
    $title = $page_data->post_title;
    ?>




    }
    ?>

    However, there is a problem. They’re displaying out of order. Since it’s going by page id, it’s going in the order that I created them, and not their set post order. Any Idea how I can fix this?

    #94991
    jamygolden
    Member

    Have you had a look at get_pages()?

    It would be something like:

    $pages = get_pages();
    foreach ( $pages as $page ) {

    $content = $page->post_content; // I'm not sure if it's post_content. print_r( $page ); to see what you should use
    $title = $page->post_title;

    $output = '

    ' . $title . '

    ';
    $output .= '
    ' . $content . '
    ';

    echo $output;

    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.