Title: Query_posts Ordering/Sorting
Last modified: August 19, 2016

---

# Query_posts Ordering/Sorting

 *  [memphis2k](https://wordpress.org/support/users/memphis2k/)
 * (@memphis2k)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/)
 * 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)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1468844)
 * 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](http://codex.wordpress.org/Template_Tags/query_posts)
   explains the arguments in detail.
 *  Thread Starter [memphis2k](https://wordpress.org/support/users/memphis2k/)
 * (@memphis2k)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1468856)
 * 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
   
       	}
       	?>
       ```
   
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1468861)
 *     ```
       query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => 'page', 'order'=>'date'));
       ```
   
 *  Thread Starter [memphis2k](https://wordpress.org/support/users/memphis2k/)
 * (@memphis2k)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1468868)
 * Got it working…
 * `query_posts(array('showposts' => 100, 'post_parent' => 106, 'post_type' => '
   page', 'orderby'=>menu_order,'order'=>ASC));`
 * Thanks
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1468900)
 * 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);
       ```
   
 *  [Vitalii Kaplia](https://wordpress.org/support/users/drop/)
 * (@drop)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1469107)
 * Спасибо, ребята! Очень ценная информация!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Query_posts Ordering/Sorting’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [query_post](https://wordpress.org/support/topic-tag/query_post/)
 * [sorting](https://wordpress.org/support/topic-tag/sorting/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [Vitalii Kaplia](https://wordpress.org/support/users/drop/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/query_posts-orderingsorting/#post-1469107)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
