好吧-结果证明很简单-因为我有某种心理障碍-menu_order
是中的变量$post
对象(感谢@brady提醒我这一点)。
@斯克里布的post on creating sortable column values 然后给出其余部分。
因此,假设调用了自定义post类型header_text
, 以下是所需的功能和挂钩:
Add a new column for the order
/**
* add order column to admin listing screen for header text
*/
function add_new_header_text_column($header_text_columns) {
$header_text_columns[\'menu_order\'] = "Order";
return $header_text_columns;
}
add_action(\'manage_header_text_posts_columns\', \'add_new_header_text_column\');
Render the column values
/**
* show custom order column values
*/
function show_order_column($name){
global $post;
switch ($name) {
case \'menu_order\':
$order = $post->menu_order;
echo $order;
break;
default:
break;
}
}
add_action(\'manage_header_text_posts_custom_column\',\'show_order_column\');
Set the column to be sortable
/**
* make column sortable
*/
function order_column_register_sortable($columns){
$columns[\'menu_order\'] = \'menu_order\';
return $columns;
}
add_filter(\'manage_edit-header_text_sortable_columns\',\'order_column_register_sortable\');