简体   繁体   中英

Change default order of pages in WordPress Admin / Backend

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

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 );

Use this snippet 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' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM