Change Post Order to Order by Last Modified Posts
If you want to list the posts in your blog view ordered by last modified date (in descending order), you can use this snippet:
add_action( 'pre_get_posts', 'order_posts_by_modified_date' );
function order_posts_by_modified_date( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'orderby', 'modified' );
$query->set( 'order', 'DESC' );
}
}
Related Posts
- Change Post Order to Last Modification Date
- Increase Upload Size when Using VestaCP
- SQL: Delete All Rows Except Last X
- Shortcode for Listing the Recent Posts or CPTs
- Shortcode Showing the Latest Posts Using Timber
- Query Posts Where Custom Field is NULL
- Query Posts Where Custom Field is Set / NOT NULL