• Ok, I want to show only one newest post on my first page, which is easy, but here’s the trick.

    I want to show the newest post from all categories except 1 (ID=1).

    I thought that with query_posts this would be piece of cake, but it’s not.. Here’s what I use:

    <?php query_posts = ('showposts=1&cat=-1'); ?>

    This brings only one post, not including the cat number 1, but the post is THE OLDEST ONE, not the newest one…

    How can I order those posts in DESC order by date?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter incomehero

    (@incomehero)

    The strangest thing is that if I rewrite that query in a different way, like:

    <?php query_posts = ('showposts=1&cat=2,3,4'); ?>

    Which includes all categories except the one with ID=1, everything is fine… But still, it would suck manually entering all those numbers every time you create a new directory…

    Thread Starter incomehero

    (@incomehero)

    Strangely that doesn’t work.

    Now I have:
    `<?php query_posts = (‘showposts=1&cat=-1&orderby=date&order=DESC’); ?>

    I also tried &orderby=ID&order=DESC but still no luck.

    It seems that whenever you enter “cat=-1” ordering functions do not work. :/

    I had the same problem and the only solution I came up with is editing the file ‘/wp-includes/query.php’ on line 1019 (WP 2.5.1), and I believe this is a bug in WordPress:


    if ( !empty($q['category__in']) || !empty($q['category__not_in']) || !empty($q['category__and']) ) {
    // -> THE FOLLOWING LINE CAUSES THE ORDERBY PROBLEM
    // $groupby = "{$wpdb->posts}.ID";
    }

    So far, this change didn’t screw anything else up on my blog.

    HTH

    Edit: it works.

    <?php query_posts('cat=-1&orderby=date&order=DESC&showposts=1'); ?>

    cat goes before showposts

    @robphas

    Is this documented somewhere?

    Thanks

    How do I fix this problem ? please be specific as the previous fix by Flowdrops is not possible anymore.

    I fixed the issue in 2.7.1 by replacing query.php file in wp-includes with the query.php file from an older version of wordpress ie 2.6.5.
    Looks like there is a bug in the latest version.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘query_posts and order by date’ is closed to new replies.