Uncategorized

wordpress: order posts by date modified

 

add this snippet to your functions.php inside your theme folder.

 

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

Leave a Reply

Your email address will not be published. Required fields are marked *