Forums

Query_posts Ordering/Sorting (7 posts)

  1. memphis2k
    Member
    Posted 3 years ago #

    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
  2. MichaelH
    Member
    Posted 3 years ago #

    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.

  3. memphis2k
    Member
    Posted 3 years ago #

    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
    
    	}
    	?>
  4. MichaelH
    Member
    Posted 3 years ago #

    query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => 'page', 'order'=>'date'));
  5. memphis2k
    Member
    Posted 3 years ago #

    Got it working...

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

    Thanks

  6. MichaelH
    Member
    Posted 3 years ago #

    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);
  7. Drop
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic