Support » Fixing WordPress » Exclude Category Returns 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/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)
  • <?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

    (@hhr_web)

    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

    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.