Title: Sort posts by modified date
Last modified: April 6, 2021

---

# Sort posts by modified date

 *  Resolved [JonWright](https://wordpress.org/support/users/wrightj2/)
 * (@wrightj2)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/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)

 *  Plugin Support [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/sort-posts-by-modified-date/#post-14285510)
 * Hi there,
 * There’s no need for this code if you wish for the WPSP list to be sorted by modified
   date.
 * There’s a UI setting for this within the WPSP edit page. Check the “More settings”
   tab.
 * Here’s how it looks like on the UI: [https://share.getcloudapp.com/L1udg9wd](https://share.getcloudapp.com/L1udg9wd)
 *  Thread Starter [JonWright](https://wordpress.org/support/users/wrightj2/)
 * (@wrightj2)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/sort-posts-by-modified-date/#post-14287280)
 * My bad, should have looked there. Thank you.
 *  Plugin Support [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * (@ejcabquina)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/sort-posts-by-modified-date/#post-14290769)
 * No problem. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Sort posts by modified date’ is closed to new replies.

 * ![](https://ps.w.org/wp-show-posts/assets/icon-256x256.png?rev=2846296)
 * [WP Show Posts](https://wordpress.org/plugins/wp-show-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-show-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-show-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-show-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-show-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-show-posts/reviews/)

## Tags

 * [modified date](https://wordpress.org/support/topic-tag/modified-date/)

 * 3 replies
 * 2 participants
 * Last reply from: [Elvin](https://wordpress.org/support/users/ejcabquina/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/sort-posts-by-modified-date/#post-14290769)
 * Status: resolved