Title: Post sort order question
Last modified: August 24, 2016

---

# Post sort order question

 *  [phudack7](https://wordpress.org/support/users/phudack7/)
 * (@phudack7)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/post-sort-order-question/)
 * I have a site with pages that need to list categories in 2 different ways. On
   the news page, all posts in the “news” category should list the most recent post
   first, but on the event page, all post in the “event” category should list in
   reverse order so the next upcoming event is at the top of the list.
 * Is there a php function I can use to change the sort order? For example, in the
   loop, can I put some logic that would say “if category = event, sort by DESC”?
 * I’ve tried doing that, but it didn’t work for me. I may just have incorrect syntax,
   but I’m not sure if I’m going about this correctly. Ive tried several plugins,
   but none seem to do what Im looking to do.
 * thanks everyone

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

 *  [Martin Robbins](https://wordpress.org/support/users/santeven/)
 * (@santeven)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/post-sort-order-question/#post-6166339)
 * You are welcome
 * For the “if” logic:
    [https://codex.wordpress.org/Conditional_Tags](https://codex.wordpress.org/Conditional_Tags)
 * For categories:
    [https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)
 * For sorting:
    [https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters)
 *  Thread Starter [phudack7](https://wordpress.org/support/users/phudack7/)
 * (@phudack7)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/post-sort-order-question/#post-6166346)
 * Thanks for the links.
    Actually, I was able to get it working using the following
   logic:
 * <?php if (is_category(array(119))){
    query_posts($query_string . “&order=DESC”);}?
   >
 * However, adding this before the loop makes the sidebar disappear. As soon as 
   I remove it, it comes back. Ive tried several “if is_category” callouts and each
   one makes the sidebar disappear. The “get_sidebar” callout is there, but its 
   returning an empty div. I’m really struggling to figure out why.
 * [http://www.wildlandspa.org/category/news/](http://www.wildlandspa.org/category/news/)

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

The topic ‘Post sort order question’ is closed to new replies.

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 2 replies
 * 2 participants
 * Last reply from: [phudack7](https://wordpress.org/support/users/phudack7/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/post-sort-order-question/#post-6166346)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
