Skip to content

Instantly share code, notes, and snippets.

@jo-snips
Created August 30, 2012 22:21
Show Gist options
  • Select an option

  • Save jo-snips/3542941 to your computer and use it in GitHub Desktop.

Select an option

Save jo-snips/3542941 to your computer and use it in GitHub Desktop.
The Events Calendar: Custom Event Order in Admin
<?php
/*-----------------------------------------------------------------------------------*/
/* Modify Event List Order in Admin
/*-----------------------------------------------------------------------------------*/
function set_custom_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 == 'tribe_events') {
// 'orderby' value can be any column name
$wp_query->set('orderby', 'start_date');
// 'order' value can be ASC or DESC
$wp_query->set('order', 'ASC');
}
}
}
add_filter('pre_get_posts', 'set_custom_post_types_admin_order');
?>
@jungerpants

Copy link
Copy Markdown

Close. Should be 'start-date' in line 13, not 'start_date.'

/-----------------------------------------------------------------------------------/
/* Modify Event List Order in Admin
/-----------------------------------------------------------------------------------/
function set_custom_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 == 'tribe_events') {

  // 'orderby' value can be any column name
  $wp_query->set('orderby', 'start-date');

  // 'order' value can be ASC or DESC
  $wp_query->set('order', 'asc');

}

}
}
add_filter('pre_get_posts', 'set_custom_post_types_admin_order');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment