简体   繁体   English

更改WordPress管理/后端中的默认页面顺序

[英]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. 我正在尝试更改WordPress后端页面的默认排序顺序。 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. 我知道这可以通过单击“标题”,“日期”或“ID”选项卡轻松完成,但这些只是一次性设置,我需要一个全局=默认解决方案。

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 :-( 我继续尝试使用这个功能,这对我来说很有意义,但它只是不适用于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. 只需在您自己的代码中将“ASC”更改为“DESC”,它就能完美运行。 Or copy and paste below mentioned code into your functions.php : 或者将下面提到的代码复制并粘贴到您的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' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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