Change the default order of custom post types in the WordPress administration. We’d like the order to be by title and not have to click the title to set the order.
Add this code to functions.php.
/* make CPT posts in admin order by title */ /* Sort posts in wp_list_table by column in ascending or descending order. */ function custom_post_order($query){ /* Set post types. _builtin => true returns WordPress default post types. _builtin => false returns custom registered post types. */ /* set the _builtin to false which will order our Custom post types by title */ $post_types = get_post_types(array('_builtin' => false), 'names'); /* The current post type. */ $post_type = $query->get('post_type'); /* Check post types. */ if(in_array($post_type, $post_types)){ /* Post Column: e.g. title */ if($query->get('orderby') == ''){ $query->set('orderby', 'title'); } /* Post Order: ASC / DESC */ if($query->get('order') == ''){ $query->set('order', 'ASC'); } } } if(is_admin()){ add_action('pre_get_posts', 'custom_post_order'); }




by Norm Euker