How to put last edited entry on top of the blog-post list?

As stated in my comment to the OP, you should make use of pre_get_posts to target change the query variables as needed before the main query is executed.

Just a tip, pre_get_posts uses the same exact parameters as WP_Query, so you can have a look at those parameters and use them to construct your pre_get_post action parameters to modify the query variables

To achieve what you are after, you need to look at the orderby and order parameters, you will want to use the value of modified for the parameter orderby.

Remember, with pre_get_posts you can target specific pages/templates by means of the conditional tags. However, this will not work on if your page you want to target is a static front page, then you will need to use WP_Query to construct a custom query with the desired parameters

You can try something like this in your functions.php. Here I am going to target only the home page

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

Leave a Comment