Title: Exclude Category Returns Oldest Posts First??
Last modified: August 20, 2016

---

# Exclude Category Returns Oldest Posts First??

 *  [hhr_web](https://wordpress.org/support/users/hhr_web/)
 * (@hhr_web)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-return-oldest-posts-first/)
 * When I exclude a category, the chronological order reverses, listing the oldest
   posts first.
 * `get_posts('numberposts=-1&category=-57');`
 * OR
 *     ```
       $args('numberposts'=>-1, 'category'=>-57)
       get_posts(#args);
       ```
   
 * – query_posts returns the same result and I cannot use it on this page because
   I am also listing posts that include this category
    – category__not_in returns
   the same result – order and orderby args have no effect
 * I’ve seen previous posts regarding this issue ([http://wordpress.org/support/topic/exclude-category-from-loop-problems](http://wordpress.org/support/topic/exclude-category-from-loop-problems),
   [http://wordpress.org/support/topic/query_posts-and-order-by-date](http://wordpress.org/support/topic/query_posts-and-order-by-date))
   as far back as version 2.7.1 and while each instance presents a different solution,
   they have all identified it as a bug in WordPress.
 * Can anyone provide a fix or an alternative method to exclude categories? Using
   WordPress 3.1.2.

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-return-oldest-posts-first/#post-2313174)
 *     ```
       <?php
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args= array(
       	'category' => -57,
       	'posts_per_page' => -1,
       	'paged' => $paged
       );
       $my_posts_array = get_posts($args);
       ?>
       ```
   
 *  Thread Starter [hhr_web](https://wordpress.org/support/users/hhr_web/)
 * (@hhr_web)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-return-oldest-posts-first/#post-2313276)
 * Thanks esmi, but this doesn’t fix the sorting issue of the posts.
 * I tried a fix suggested in one of the replies for this forum post: [http://wordpress.org/support/topic/query_posts-and-order-by-date](http://wordpress.org/support/topic/query_posts-and-order-by-date)
 * He commented out a $groupby declaration within the query.php file in his WP 2.5.1.
 * I found the similar line of code in my query.php (WP3.1.2) line 2234:
 *     ```
       if ( !empty( $this->tax_query->queries ) || !empty( $q['meta_key'] ) ) {
       			//$groupby = "{$wpdb->posts}.ID"; when excluding category ID this reverses sorting of posts to ASC by postdate
       		}
       ```
   
 * This fixed the specific post list I needed to target and after a cursory review
   of several post lists throughout the site, it does not appear to have broken 
   anything.

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

The topic ‘Exclude Category Returns Oldest Posts First??’ is closed to new replies.

## Tags

 * [exclude category](https://wordpress.org/support/topic-tag/exclude-category/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [hhr_web](https://wordpress.org/support/users/hhr_web/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-return-oldest-posts-first/#post-2313276)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
