-1

I am trying to display some posts in ascending order beginning with the first created and ending with the most recently created post. Any help is appreciated. Here is my code:

<?php
$numofmebers = '-1';
if ( empty($_GET['page_id_all']) ) $_GET['page_id_all'] = 1;
    $count_post = 0;
        query_posts( array( 'posts_per_page' => '-1', 'post_type' => 'coach-instructor' ,'post_status' => 'publish') );
        while ( have_posts()) : the_post();
            $count_post++;
        endwhile;
            if ( $node->instructor_pagination == "Single Page" ) {$node->instructor_page_num = -1;}
            query_posts( array('posts_per_page' => "$node->instructor_page_num", 'paged' => $_GET['page_id_all'], 'post_type' => 'coach-instructor' ,'post_status' => 'publish') ); 
        $counter_news = 0;
        while ( have_posts()) : the_post();
        $counter_news++;
        $image_id = get_post_thumbnail_id ( $post->ID );
        $coach_istructor_meta = get_post_meta($post->ID, "cs_coach_istructor_meta", true);
            if ( $coach_istructor_meta <> "" ) {
                $xmlObject_author = new SimpleXMLElement($coach_istructor_meta);
                    $about = $xmlObject_author->about;
                    $specialism = $xmlObject_author->specialism;
                    $qualifications = $xmlObject_author->qualifications;
                    $philosophy = $xmlObject_author->philosophy;
                    $contact = $xmlObject_author->contact;
            }
            else {
                $about = '';
                $specialism = '';
                $qualifications = '';
                $philosophy = '';
                $contact = '';
            }
?>
1
  • 1
    Ascending or descending?
    – fuxia
    Commented Jan 1, 2013 at 0:52

2 Answers 2

1

Keep in mind that query_posts is best avoided as it has negative effects on the main loop. A better approach would be a new instance of WP_Query or changing the query arguments for the main loop.

To get the order you want, try adding the following to your args:

array( 'posts_per_page' => '-1', 'post_type' => 'coach-instructor' ,'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC')
1
  • Thank you for the help. It worked. I'm still learning PHP and operating within the Wordpress framework. This will help me in the future as well.
    – Tom Geoco
    Commented Jan 1, 2013 at 1:58
-2
$orde = ('orderby','date');
$ordr = ('order','DESC');
$query = array(
    'post_type' => array('posts_per_page'),
    'orderby'   => $orde,
    'order'     => $ordr
);
1
  • Welcome to WPSE! The parameters you are passing to the query are invalid. orderby can be an array, but in that case the "sort column" (precisely the value denoting the column) must be a key in the array, not a value. Using an array in orderby should look like this: $args = array( "orderby" => array("date"=>"DESC") ).
    – nmr
    Commented Jan 14, 2023 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.