Sortable Columns

<?php

/* ~~~~~~~~~~~~~~~~~~ Columns ~~~~~~~~~~~~~~~~~~ */

/* Add Columns */
function bz_add_columns($defaults){
if($_GET['post_type'] != 'bz_league') return $defaults;
$defaults['bz_league_start_date'] = __('Start Date');
return $defaults;
}

/* Get Column Data */
function bz_get_column_data($column,$id){
switch($column){
case 'bz_league_start_date':
echo get_post_meta($id,'bz_league_start_date',true);
break;
}
}

function bz_client_name_column_register_sortable($columns){
$columns['bz_league_start_date'] = 'bz_league_start_date';
return $columns;
}

function bz_client_name_column_orderby($vars){
if(isset($vars['orderby']) && 'bz_league_start_date' == $vars['orderby']){
$vars = array_merge($vars,array(
'meta_key' => 'bz_league_start_date',
'orderby' => 'meta_value'
));
}
return $vars;
}

add_filter('manage_bz_league_posts_columns','bz_add_columns');
add_action('manage_bz_league_posts_custom_column','bz_get_column_data',10,2);
add_filter('manage_edit-bz_league_sortable_columns','bz_client_name_column_register_sortable');
add_filter('request','bz_client_name_column_orderby');

?>

0 Comments

You must be logged in to post a comment.