Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mmarj/d86ffa9f0cc1d776626185a03e40b23d to your computer and use it in GitHub Desktop.
Save mmarj/d86ffa9f0cc1d776626185a03e40b23d to your computer and use it in GitHub Desktop.
Set the order of the pages/posts in the admin section according to the last modified/editing date
//* @ Method 1
// Set the order of the pages/posts in the admin section descending according to the editing date [for all post/page type]
function orderby_modified_posts( $query ) {
if( is_admin() ) {
$query->set( 'orderby', 'modified' );
$query->set( 'order', 'desc' );
}
}
add_action( 'pre_get_posts', 'orderby_modified_posts' );
/* @ Method 2
// Set the order of the pages/posts in the admin section descending according to the editing date [for specific page type]
function orderby_modified_posts( $query ) {
if( is_admin() and isset($_GET['post_type']) and $_GET['post_type'] === 'page') {
$query->set( 'orderby', 'modified' );
$query->set( 'order', 'asc' );
}
}
add_action( 'pre_get_posts', 'orderby_modified_posts' );
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment