Title: Query posts by category ~ not working
Last modified: August 19, 2016

---

# Query posts by category ~ not working

 *  [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/)
 * I’m trying to query the posts by category
 * <?php query_posts( ‘cat=-12&orderby=category&order=DESC’ ); ?>
 * However, what it puts out seems totaly random….The numbers are the category ID&
   theater is the category name….
 * # Sucker Punch
 *  * Theater 4
 * 17March 22, 2011
 * # Limitless
 *  * Theater 3
 * 16
 * # The Lincoln Lawyer
 *  * Theater 2
 * 15
 * # Diary of a Wimpy Kid 2
 *  * Theater 1
 * 14
 * # Red Riding Hood
 *  * Theater 6
 * 19
 * # Paul
 *  * Theater 5
 * 18
 * # Mars Needs Moms
 *  * Theater 4
 * 17March 18, 2011
 * # Paul
 *  * Theater 1
 * 14
 * # The Adjustment Bureau
 *  * Theater 6
 * 19
 * # Battle: Los Angeles
 *  * Theater 3
 * 16

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994544)
 * There’s no `orderby=category` in query_posts.
 *  Thread Starter [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994546)
 * Well, that would explain why it doesn’t work…. What code should I use to get 
   it to order by the category…. I just saw that code in lots of places on this 
   site, guess that why other people had problems too.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994557)
 * [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994565)
 * Yes, I’ve read that & found no reference on how to make the posts sort by category
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994567)
 * That’s because there **isn’t** an option to order by category. The only way to
   do this would be to have multiple Loops – each calling one category at a time.
 *  Thread Starter [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994609)
 * Well, I need to query posts not in category 12. They need to be sorted by date
   first, then by category. Can you give me any more specifics on how to make this
   happen?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994620)
 * That is going to take a **lot** of work. You’d need to grab the results of the
   standard query (as opposed to displaying it) and then start looping through it
   to pull out/display posts from a specific category. Then repeat for every category
   that you want to display.
 *  Thread Starter [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994796)
 * Ok…I have my code narrowed down & closer to what I want. Hoping someone can help
   me finalize it
 * Need to first query the posts to only pull in those whose movieStartDate value
   is less than or equal to today….then have it loop through the code to sort by
   category
 * ****query_posts (meta_key=’movieStartDate’&meta_value<=time())
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_

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

The topic ‘Query posts by category ~ not working’ is closed to new replies.

## Tags

 * [order by](https://wordpress.org/support/topic-tag/order-by/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)
 * [sort by](https://wordpress.org/support/topic-tag/sort-by/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/query-posts-by-category-not-working/#post-1994796)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
