Title: WP_Query sorting does not work
Last modified: August 20, 2016

---

# WP_Query sorting does not work

 *  [jundolor](https://wordpress.org/support/users/jundolor/)
 * (@jundolor)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/)
 * I’m having problems trying to do a simple sorting task. I’ve entered the code
   below in category.php”
 *     ```
       $queryP = new WP_Query( array ( 'orderby' => 'title', 'order' => 'DESC' ) );
       #$queryP->query();
   
       while ( $queryP->have_posts() ) : $queryP->the_post();
       	echo '<li>';
       	the_title();
       	echo '</li>';
       endwhile;
       ```
   
 * Titles are not sorted the way I had hoped it would. What did I miss out? I’m 
   running WordPress 3.2
 * Thanks

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/#post-2334975)
 * Remove `#$queryP->query();`
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/#post-2334979)
 * If it is the categories page then you do not need WP_Query() as [query_posts($args);](http://codex.wordpress.org/Function_Reference/query_posts)
   can re-sort the existing post set, if I am right without re-doing the query.
 *     ```
       <?php
       $query='orderby=title&order=DESC';
       query_posts($query);
       ?>
   
       <?php if ( have_posts() ) : ?>
       ```
   
 * HTH
 * David
 *  Thread Starter [jundolor](https://wordpress.org/support/users/jundolor/)
 * (@jundolor)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/#post-2335218)
 * Thanks, but the sorting still does not work. I’ve rewritten the code as follows:
 *     ```
       <?php
       $query='cat=3&orderby=title&order=DESC';
       query_posts($query);
       ?>
   
       <?php while ( have_posts() ) : the_post(); ?>
       ```
   
 * The query gets to select the posts in the category, but still the sorting does
   not work.
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/#post-2335253)
 * Ok,
    I have modified one of my downloadable twenty eleven child themes which 
   outputs a [page of posts](http://digitalraindrops.net/2011/09/wordpress-twenty-eleven-a-page-of-posts/),
   it uses custom fields and there is a download in the link.
 * Then grab [this code](http://pastebin.com/i7gefyWL) from pastebin and replace
   all the code in the download file page-category.php
 * The additional Custom Field is:
    **ordered** The options: (Default ID) ‘none’,‘
   ID’, ‘author’, ‘title’ , ‘date’ , ‘modified’, ‘parent’, ‘rand’, ‘comment_count’,‘
   menu_order’
 * I tested this with custom fields:
 * category = blog (one of my categories)
    asc = true ordered = title
 * category = blog (one of my categories)
    ordered = title
 * category = blog (one of my categories)
    ordered = rand
 * All worked as expected!
 * HTH
 * David
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/#post-2335285)
 * I [extended my page of posts](http://wordpress.org/support/topic/free-child-theme-twenty-eleven-page-of-posts-extended?replies=1#post-2382181)
   to use meta data, you might find the code in the page template handy.
 * Regards
 * David

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

The topic ‘WP_Query sorting does not work’ is closed to new replies.

## Tags

 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-sorting-does-not-work/#post-2335285)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
