Make custom post type column sortable
My site has two custom types: Auction and Lot. Lots are connected to an Auction via the post_parent field. I added an Auction column to the Lots list in the admin area.
function theme_lot_custom_columns($columns){
$new = array();
foreach($columns as $key = $value) {
if ($key=='date') {
// Put the Auction column before the Date column
$new['auction'] = __('Auction');
}
$new[$key] = $value;
}
return $new;
}
add_filter('manage_lot_posts_columns', 'theme_lot_custom_columns');
function theme_lot_custom_column($column, $post_id) {
if ($column === 'auction'){
$post = get_post($post_id);
if ($post-post_parent) {
$post_parent = get_post($post-post_parent);
echo 'a href="' . get_edit_post_link($post_parent-ID). '"' . $post_parent-post_title . '/a';
}
}
}
add_action('manage_lot_posts_custom_column', 'theme_lot_custom_column', 5, 2);
I'd like to make this Auction column sortable alphabetically by the auction title. I thought that adding the following code was enough, but no.
function theme_lot_sortable_columns($columns) {
$columns['auction'] = 'auction';
return $columns;
}
add_filter('manage_edit-lot_sortable_columns', 'theme_lot_sortable_columns');
Any help would be appreciated.
Thanks!
Topic columns custom-post-types sort Wordpress
Category Web