Wordpress - How to order posts of a custom post type by date DESC in dashboard Admin?
Alright, You can just hook into the filter pre_get_posts and check is_admin. Put this in your theme or plugin:
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') {
$wp_query->set('orderby', 'date');
$wp_query->set('order', 'DESC');
}
}
}
add_filter('pre_get_posts', 'wpse_81939_post_types_admin_order');
I also would shange the post_type "Videos" to lowercase like "video".
The example above disables the ordering feature by clicking columns.
Sortable & for multiple custom post types:
function wpse_819391_post_types_admin_order( $wp_query ) {
if ( is_admin() && !isset( $_GET['orderby'] ) ) {
// Get the post type from the query
$post_type = $wp_query->query['post_type'];
if ( in_array( $post_type, array('videos','news','text') ) ) {
$wp_query->set('orderby', 'date');
$wp_query->set('order', 'DESC');
}
}
}
add_filter('pre_get_posts', 'wpse_819391_post_types_admin_order');