Site logo

Archived topic

Sort posts by modified date both on blog page & via WP Show Posts

3 replies · Started by Jon on April 6, 2021

Viewing posts 1–4 of 4

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?

Let me know if you'd sooner I raise this in the WP Show Posts support forum?

Thanks in advance

OK will do.

Thanks!

This archived topic is closed to new replies.