Created
August 16, 2022 19:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* @ 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