Have you ever wished to set blog post to show by modified date? It should not be available by default in WordPress in Settings > Reading?
One can Order the archive post to show by various parameters with the help of action hook pre_get_posts (rewrite default loop) with the help of wp_query and conditional tag.
Order Post by Modified Date
Use the following in functions.php of your child theme.
add_action ( 'pre_get_posts', function ( $query ) { if ( !is_admin() && $query->is_main_query() && ( $query->is_home() || $query->is_category() ) ) { $query->set( 'orderby', 'modified' ); } });
Here, parameter orderby is set to “modified”. Find all the available parameters and use with a custom $query and restrict it with Conditional Tags.
How do I also add costom field – so it would order Post with costom field + modified being first on top?
You will need to create a custom loop to output custom fields.