Last active
July 22, 2018 22:25
-
-
Save arelthia/5bb741ee03dc4462f70ea5b15d7b4898 to your computer and use it in GitHub Desktop.
Change order of custom post type on admin edit.php screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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