Title: Reading: Latest Modified Posts First
Last modified: December 4, 2016

---

# Reading: Latest Modified Posts First

 *  [longnha](https://wordpress.org/support/users/longnha/)
 * (@longnha)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/)
 * Hello,
 * On my wordpress site, the reading is display latest post first and I want to 
   change it a bit by display “latest modified post” first.
 * Could someone recommend a way to do the trick please?
 * Thank you for your help.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [simplerthansimplest](https://wordpress.org/support/users/simplerthansimplest/)
 * (@simplerthansimplest)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/#post-8512245)
 * Hi [@longnha](https://wordpress.org/support/users/longnha/),
 * Place below code in your active theme’s function.php and you will get what you
   want.
    add_action( ‘pre_get_posts’, ‘alter_query_to_show_modified_post_first’);
 * function alter_query_to_show_modified_post_first( $query ) {
    if( !is_admin()&&
   $query->is_main_query() ) { $query->set( ‘orderby’, ‘modified’ ); } }
 * Looking forward to hear from you.
 *  Thread Starter [longnha](https://wordpress.org/support/users/longnha/)
 * (@longnha)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/#post-8512296)
 * Hi [@simplerthansimplest](https://wordpress.org/support/users/simplerthansimplest/)
 * Wonderful, it works. Thank you very much.
 * A bit need to change for anyone who need it.
 *     ```
       add_action( 'pre_get_posts', 'alter_query_to_show_modified_post_first' );
   
       function alter_query_to_show_modified_post_first( $query ) {
       if($query->is_main_query() ) {
       $query->set( 'orderby', 'modified' );
       }
       }
       ```
   
 *  [simplerthansimplest](https://wordpress.org/support/users/simplerthansimplest/)
 * (@simplerthansimplest)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/#post-8512314)
 * Good to hear that it worked.
    Removing admin condition will list recently modified
   post first both on admin side and frontend. If it is that you wanted then its
   COOL 🙂
 *  Thread Starter [longnha](https://wordpress.org/support/users/longnha/)
 * (@longnha)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/#post-8512325)
 * My apologize, I removed !is_admin it to test and forgot to add it back. Updated
   code:
 *     ```
       add_action( 'pre_get_posts', 'alter_query_to_show_modified_post_first' );
   
       function alter_query_to_show_modified_post_first( $query ) {
       if(!is_admin() && $query->is_main_query() ) {
       $query->set( 'orderby', 'modified' );
       }
       }
       ```
   
 * Thank [@simplerthansimplest](https://wordpress.org/support/users/simplerthansimplest/)
 *  Thread Starter [longnha](https://wordpress.org/support/users/longnha/)
 * (@longnha)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/#post-8512421)
 * Seem like there have a conflict! I’ve many scheduled posts, when a scheduled 
   post is published, it no longer display at top because the code check ‘modified
   date’ of scheduled post, not ‘publish date’
 * Is there a way for ‘latest modified’ and ‘latest post’ to work together?
 * Thank you.
    -  This reply was modified 9 years, 5 months ago by [longnha](https://wordpress.org/support/users/longnha/).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Reading: Latest Modified Posts First’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [longnha](https://wordpress.org/support/users/longnha/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/reading-latest-modified-posts-first/#post-8512421)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
