Change default page order in WordPress Admin / Backend
I am trying to change the default sort order for pages in my WordPress backend. I know it's easy to do this by clicking on the Title, Date, or Id tab, but these are just one-off settings and I need a global default solution.
I went ahead and tried to use this feature, which makes sense to me, but it just doesn't work with WordPress 4.2.3: --(
function set_post_order_in_admin( $wp_query ) {
global $pagenow;
if ( is_admin() && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
$wp_query->set( 'orderby', 'title' );
$wp_query->set( 'order', 'asc' );
}
}
add_filter('pre_get_posts', 'set_post_order_in_admin', 5 );
Any idea why this doesn't work anymore? How can I achieve this?
Thanks, hello Henning
+3
source to share
2 answers
Just change the order of "ASC" to "DESC" in your own code, it will work fine. Or copy and paste the below code into your functions. Php:
function set_post_order_in_admin( $wp_query ) {
global $pagenow;
if ( is_admin() && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
$wp_query->set( 'orderby', 'title' );
$wp_query->set( 'order', 'DESC' );
}
}
add_filter('pre_get_posts', 'set_post_order_in_admin', 5 );
+1
source to share
Use this piece of code:
function set_post_order_in_admin( $wp_query ) {
global $pagenow;
if ( is_admin() && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
$wp_query->set( 'orderby', 'title' );
$wp_query->set( 'order', 'DSC' );
}
}
add_filter('pre_get_posts', 'set_post_order_in_admin' );
0
source to share