Support » Fixing WordPress » Sort posts by last updated/modified

  • Resolved stevechatterton


    I’m looking for a simple way to display the recent posts on my home page not in the order that they were created but in the order they were last modified. The site is about book reviews and we link to new reviews as they come up elsewhere & we want to show our freshest content right up front.

    Any ideas? I’ve been trying to figure it out for about a week now and I keep coming up empty handed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • query_posts offers the orderby=modified argument you could use.

    That would be fantastic, MichaelH, except for one thing:

    The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page.

    This has to be used for two lists side by side on one page. See the 2 lists under the New York Times Best Sellers box on this page for clarification:

    If I can do it without a plugin I’d be very thankful, as I get a few memory problems working in the admin module as it is & don’t want to aggravate the situation.

    List will display 5 posts in last modified order:

      'orderby'=> 'modified',
      'order' => 'ASC',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 5,
      'caller_get_posts'=> 1
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    wp_reset_query();  // Restore global post data stomped by the_post().

    You’re a brilliant man, MiachaelH. Oddly enough, it’s almost like you were looking at my source code. Your suggested modification worked itself in almost seamlessly.

    I did change the order to DESC, though. I got a lot of really old posts with ASC. Other than that, this is exactly what I’ve been looking for. Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort posts by last updated/modified’ is closed to new replies.