Skip to content

Instantly share code, notes, and snippets.

@srikat
Created March 30, 2015 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srikat/f67df4e2b8a158d285e6 to your computer and use it in GitHub Desktop.
Save srikat/f67df4e2b8a158d285e6 to your computer and use it in GitHub Desktop.
Display Archive pages by Modified Date in WordPress
add_action( 'pre_get_posts', 'sk_order_posts_by_modified' );
/**
* Arrange Posts by last modified with the most recently updated ones at the top
*
* @author Sridhar Katakam
* @author Bill Erickson <- Boss
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function sk_order_posts_by_modified( $query ) {
if( $query->is_main_query() && !is_admin() && is_archive() ) {
$query->set( 'orderby', 'modified' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment