Sort posts by modified date
-
Hi – I am outputting my posts on my ‘blog’ page as normal and then using your WP Show Posts plugin to also show them in a content area on my homepage. I have changed everything to show the post updated date rather than the published on date but I am now trying to get the sort order to reflect the same.
I have used this code (written by Tom)
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' ); } } );
This works for my blog page but not on my homepage (i.e. for WP Show Posts). I had hoped/assumed it would work for both. Is there a way to modify the code so that it also works for the home page/WP Show Posts?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Sort posts by modified date’ is closed to new replies.