Instantly share code, notes, and snippets.

@pintop /admin.php
Last active Jul 22, 2018

Embed
What would you like to do?
Change order of custom post type on admin edit.php screen
/*
* Change order of custom post type on admin edit.php screen from name to date
* https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function ptc_admin_order( $wp_query ) {
if (is_admin()) {
$post_type = $wp_query->query['post_type'];
if ( $post_type == 'ptc_clients' || $post_type == 'ptc_proposals' ) {
$wp_query->set('orderby', 'date');
}
}
}
add_filter('pre_get_posts', 'ptc_admin_order');
/*
* Change order of custom post type on admin edit.php screen from name to date
* https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*/
function ptc_admin_order( $wp_query ) {
if (is_admin()) {
$post_type = $wp_query->query['post_type'];
if ( $post_type == 'ptc_clients' || $post_type == 'ptc_proposals' ) {
$wp_query->set('orderby', 'date');
//If you set the order to desc the colun is not sortable
$wp_query->set('order', 'DESC');
}
}
}
add_filter('pre_get_posts', 'ptc_admin_order');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment