WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Mini Loop - How to put most recent post on top? (7 posts)

  1. rtilney
    Member
    Posted 6 years ago #

    Hi all,

    I've got the mini-loop running on a static home page (www.ganning.com/new-1029/index.php) setup as a news listing. It works fine, but the problem is it is displaying the most recent posts at the bottom of the list rather than the top. Does any one know how to change the sort order by most recent post in the mini loop. I'm using the exact code from the WP mini loop instructions.

    I appreciate the help!

  2. Kafkaesqui

    Posted 6 years ago #

    "I'm using the exact code from the WP mini loop instructions."

    If you mean this:

    http://codex.wordpress.org/Creating_a_Static_Front_Page#Adding_a_Mini-Loop

    Change:

    ORDER BY 'ID' DESC

    to:

    ORDER BY 'post_date' DESC

  3. rtilney
    Member
    Posted 6 years ago #

    Hi Kafkaesqui,

    I tried that and it still displays the same order. Here is my exact code:

    <?php
    $how_many=15; //How many posts do you want to show
    require_once("news/wp-config.php"); // Change this for your path to wp-config.php file ?>

    <id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
    WHERE post_type=\"post\" AND post_status= \"publish\" ORDER BY 'post_date' DESC LIMIT ".$how_many);
    foreach($news as $np){
    printf ("%s<br><br>", $np->ID,$np->post_title);
    }?>

    Any advice?

    Thank you.

  4. Kafkaesqui

    Posted 6 years ago #

    Change your $news line to:

    $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
    WHERE post_type=\"post\" AND post_status= \"publish\" ORDER BY post_date DESC LIMIT ".$how_many);

    Slipped up suggesting quotes around post_date.

  5. rtilney
    Member
    Posted 6 years ago #

    Thanks Kafkaesqui, it worked like a charm!

  6. stlytm
    Member
    Posted 6 years ago #

    Where do you find these codes to change

  7. stlytm
    Member
    Posted 6 years ago #

    It was easy to do it in version 2.3.3, but in 2.5 I am lost so far.

Topic Closed

This topic has been closed to new replies.

About this Topic