The MU forums have moved to WordPress.org

Using a current_page / get_results code - need to sort the results (2 posts)

  1. adam533
    Member
    Posted 14 years ago #

    Hello. I am still learning Wordpress but have been picking it up very well as I go along. Tonight I am stuck though and need help :)

    I found the code on these forums and it is working as I was hoping (pulling the content from all the child pages of the parent and displaying on one page). I need to know how to sort the results though, where would I add that into this code?

    <?php
    $current_page = $post->ID;
    $querystr = "
    	SELECT * from $wpdb->posts
    	WHERE post_type = 'page'
    	AND post_parent = $current_page
    	";
    
    $child_pages = $wpdb->get_results($querystr, OBJECT);
    if ($child_pages):
    foreach($child_pages as $post) :
    setup_postdata($post); ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endforeach; ?>
    <?php else : ?>
    // Do stuff when no child page available
    <?php endif; ?>

    Thank You

  2. adam533
    Member
    Posted 14 years ago #

    Should have waited five minute before posting my question :) I just decided to try some things I have learned and guess what, one of them worked!

    SELECT * from $wpdb->posts
    	WHERE post_type = 'page'
    	AND post_parent = $current_page
    	(Added This Line) ORDER BY post_date

    Maybe this post will help someone in the future though

About this Topic