Skip to content

Instantly share code, notes, and snippets.

@caratage
Created November 23, 2012 19:26
Show Gist options
  • Save caratage/4136937 to your computer and use it in GitHub Desktop.
Save caratage/4136937 to your computer and use it in GitHub Desktop.
Order custom post type columns in admin on load
function set_artist_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 == 'artist') {
// check if parameter is not set yet
if (!isset($_GET['orderby'])) {
// 'orderby' value can be any column name
$wp_query->set('orderby', 'title');
// 'order' value can be ASC or DESC
$wp_query->set('order', 'ASC');
}
}
}
}
add_filter('pre_get_posts', 'set_artist_post_types_admin_order');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment