Wordpress 设置后台自定义post 排序

创建新的 Post type时,文章在后台默认使用 Titile 列进行升序排序,但是通常情况下我们需要按日期 Date 进行降序排序,

function wpse_81939_post_types_admin_order( $wp_query ) {
  if (is_admin()) {

    // Get the post type from the query
    $post_type = $wp_query->query['post_type'];

    if ( $post_type == 'Videos') {    // Videos 可以替换为你的 custom post type

      $wp_query->set('orderby', 'date');

      $wp_query->set('order', 'DESC');
    }
  }
}
add_filter('pre_get_posts', 'wpse_81939_post_types_admin_order');

参考链接:

https://wordpress.stackexchange.com/questions/81939/how-to-order-posts-of-a-custom-post-type-by-date-desc-in-dashboard-admin

原文地址:https://www.cnblogs.com/ryanzheng/p/10765663.html