Sorting custom post type columns in admin
-
I’ve read several threads on thsi but can’t find an answer.
I’ve got a custom post type called events and I’ve already made the ‘date’ column sortable BUT…
I’ve set up the dates to show in a pretty way (eg Thursday 1st June 2001) so the posts sort by that rather than the custom field data (eg. 2011-06-01)
In other words I want to diplay the ‘pretty’ date but sort by the actual date from the database.
I’ve got this but it doesn’t do anything:
`add_filter( ‘request’, ‘will_eventdate_column_orderby’ );
function will_eventdate_column_orderby( $vars ) {
if ( isset( $vars[‘orderby’] ) && ‘start_datetime’ == $vars[‘orderby’] ) {
$vars = array_merge( $vars, array(
‘meta_key’ => ‘start_datetime’,
//’orderby’ => ‘meta_value_num’, // does not work
‘orderby’ => ‘meta_value’
//’order’ => ‘asc’ // don’t use this; blocks toggle UI
) );
}
return $vars;
}
- The topic ‘Sorting custom post type columns in admin’ is closed to new replies.