Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default order of pages in WordPress Admin / Backend

Tags:

php

wordpress

I am trying to change the default sorting order of the pages in my WordPress backend. I know this can easily be done by clicking on the tab "Title", "Date" or "ID" but those are merely one-time settings and I need a global = default solution.

I went ahead and tried using this function which to me makes perfect sense 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 is not working any more? How can I achieve that?

Thanks + regards, Henning

like image 948
Leander Avatar asked Jul 31 '15 11:07

Leander


1 Answers

Just change order "ASC" to "DESC" in your own code, it will work perfectly. Or copy and paste below mentioned 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 );
like image 170
WpTricks24 Avatar answered Oct 21 '22 09:10

WpTricks24