• Hello all,

    I am running WP 2.9.2 and having a problem sorting/ordering my query for posts. I think I need to change the (ASC) ascending & (DESC) descending order. I’ve spent a few hours on this and checked the documentation and with no luck.

    In a nutshell, here is what I have.

    query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => 'page'));
    
    		while (have_posts()) {
    
    			the_post();
    
    			?>
    			<a href="<?php the_permalink() ?>" class="grid-product">		<?php the_title(); ?><br />
    			</a>
    		<?php }
    
    		wp_reset_query();  // Restore global post data
Viewing 6 replies - 1 through 6 (of 6 total)
  • To resort the order of posts, using the WordPress Default theme for example, in the wp-content/themes/default/index.php file, just before the line:
    <?php if (have_posts()) : ?>

    put this:

    <?php query_posts($query_string . '&orderby=date&order=ASC'); ?>

    The query_posts() article explains the arguments in detail.

    Thread Starter memphis2k

    (@memphis2k)

    Ok, i’m still puzzled. I need to keep the Array in the query_post but how can I add the order=ASC and not get a PHP error? I’m using it to generate specific posts, but the order is backwards. I’d like to sort by Page Order in WP. Its doing it fine, just backwards.

    <?php if ( (is_page('Products')) )  {
    
    		query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => 'page'));
    
    		while (have_posts()) {
    
    			the_post(); // vital
    
    			?>
    			<a href="<?php the_permalink() ?>" class="grid-product"><?php the_title(); ?></a>
    		<?php }
    
    		wp_reset_query();  // Restore global post data
    
    	}
    	?>
    query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => 'page', 'order'=>'date'));
    Thread Starter memphis2k

    (@memphis2k)

    Got it working…

    query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => 'page', 'orderby'=>menu_order,'order'=>ASC));

    Thanks

    Darn, I thought I had the ASC there…

    But this would be better (note–put this in format easier to read)

    $args=array(
      'post_parent' => 106,
      'order'=>'ASC',
      'orderby'=> 'menu_order',
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 100
    );
    query_posts($args);

    Спасибо, ребята! Очень ценная информация!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Query_posts Ordering/Sorting’ is closed to new replies.