How to Order Posts by Modified Date in WordPress

By default, your WordPress website's blog homepage displays all published posts (not pages) in reverse chronological order, with the most recently published post at the top. That is for the convenience of returning visitors who come to read your latest posts, as well as for the convenience of new visitors who are unlikely to be pleased with having to go through several steps to see your latest posts.

But if you don't like that above "sort posts by published date" behavior and need to "sort posts by modified date", then select a code given below according to your need and add it into your theme's "functions.php" file.

Code 1:

Sort Homepage Posts by Modified Date:

function themesdna_sort_homepage_posts_by_modified_date( $query ) {
    if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
        $query->set( 'orderby', 'modified' );
        $query->set( 'order', 'DESC' );
    }
}
add_action( 'pre_get_posts', 'themesdna_sort_homepage_posts_by_modified_date' );

Code 2:

Sort Homepage, Archive Pages (Category Pages, Tag Pages,...), Search Pages Posts by Modified Date:

function themesdna_sort_posts_by_modified_date( $query ) {
    if( $query->is_main_query() && ! is_admin() && ( $query->is_home() || $query->is_search() || $query->is_archive() ) ) {
        $query->set( 'orderby', 'modified' );
        $query->set( 'order', 'DESC' );
    }
}
add_action( 'pre_get_posts', 'themesdna_sort_posts_by_modified_date' );

Note: If you don't like to edit the functions.php file of your theme, you can use a plugin like "Code Snippets" to run custom code snippets on your site.

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
TidyMag PRO WordPress Theme

TidyMag PRO

If you like TidyMag free WordPress Theme, you will love the premium version. TidyMag PRO is easy to use, feature-rich,...

$25.00
PowerWP PRO WordPress Theme

PowerWP PRO

If you like PowerWP free WordPress Theme, you will love the premium version. PowerWP PRO is an easy to use,...

$25.00
Clean Grid PRO WordPress Theme

Clean Grid PRO

If you like Clean Grid free WordPress Theme, you will love the premium version. Clean Grid PRO is an elegant,...

$25.00
GridMode PRO WordPress Theme

GridMode PRO

Are you using the GridMode free WordPress Theme and looking for more advanced features? GridMode PRO theme is developed for...

$25.00
WriteMag PRO WordPress Theme

WriteMag PRO

WriteMag PRO is improved and feature-rich version of WriteMag Free WordPress Theme. When compare with the WriteMag free version, PRO...

$25.00
MintWP PRO WordPress Theme

MintWP PRO

If you like free version of MintWP WordPress Theme, you will love the premium version. MintWP PRO is an improved...

$25.00
GridHot PRO WordPress Theme

GridHot PRO

If you have tried GridHot Free WordPress Theme, then you will love the premium version. GridHot PRO version has color...

$25.00
MagPal PRO WordPress Theme

MagPal PRO

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 56 WordPress themes.