• Resolved Fretless

    (@fretless)


    I’m writing an historical journal set in the 1800’s. At the moment I’m posting entries not in chronological order. For instance I might go from 1840 to 1855 then back to 1835. I’ve hacked WordPress so that it it gives me the correct dates etc, but – as you’d expect – the program started slotting each new entry in it’s chronologically correct dated format.

    Now the problem with that is that each new entry gets “lost” in the mix and end up not displaying in the order of their WordPress ID. I further hacked my “classes.php” by replacing some of the code with:

    $request = ” SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1″.$where.” ORDER BY ID $limits”;

    as instructed by one of the posts here. That works as far as I can tell. Now the posts are referenced by their ID numbers on the main page rather than their dates. The only problem is that it lists the older post at the top and the newer posts at the bottom.

    In short, is there a way to reverse this so that the newer posts are at the top?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Change ORDER BY ID $limits to ORDER BY ID $limits desc.

    Thread Starter Fretless

    (@fretless)

    Thanks ifelse, but I get a syntax error when that happens:

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘desc’ at line 1]
    SELECT DISTINCT * FROM wp_posts WHERE 1=1 AND post_date_gmt <= ‘2005-10-27 14:23:59’ AND (post_status = “publish” OR post_author = 1 AND post_status != ‘draft’ AND post_status != ‘static’) GROUP BY wp_posts.ID ORDER BY ID LIMIT 0, 5 desc

    Any other ideas?

    Thread Starter Fretless

    (@fretless)

    OK, I think I’ve worked it out now. The “DESC” was in the wrong place. Instead of:

    $request = ” SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1″.$where.” ORDER BY ID $limits desc”;

    it should be….

    $request = ” SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1″.$where.” ORDER BY ID DESC $limits”;

    Thanks again for helping me out.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sorting by post ID – New on top’ is closed to new replies.