If I add a custom post type (example code below), in the admin page for the new custom post type the posts are sorted by ID by default. Is there a way to set the default sort order to the post title instead (only for this new custom post type)?
$labels = array(
'name' => 'States',
'singular_name' => 'State',
'add_new' => __( 'Add State' ),
'add_new_item' => __( 'Add New State' ),
'edit_item' => __( 'Edit State' ),
'new_item' => __( 'New State'),
'view' => __( 'View State'),
'view_item' => __( 'View State'),
'search_items' => __( 'Search States'),
'not_found' => __( 'No States found' ),
'not_found_in_trash' => __( 'No States found in trash' ),
'parent' => __( 'Parent State')
);
$args = array('public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'labels' => $labels,
'supports' => array( 'title','editor')
);
register_post_type( 'states', $args );
You could force the order via
pre_get_posts
:I found this answer was better here (altered to suit question):
Please note that se91124_order_post_type can be changed to any function name, States is the post_type name or label, the orderby title can be anything you like (e.g. menu_order), and obviously ASC can be changed for DESC.
Original from URL: