我已经激活了Order 我的“公文包”CPT的功能,并已根据各自的Order 我提供的价值观。
不幸的是,我发现这段代码锁定了“公文包”项目在admin中的显示顺序;我无法切换Title 升序/降序功能,也无法按此列表排序Date.
我的目标是使用Order 但我仍然希望能够利用Title/Date 在管理中排序。
//add order column to admin listing screen
function add_new_portfolio_column($post_columns) {
$post_columns[\'menu_order\'] = "Order";
return $post_columns;
}
add_action(\'manage_edit-portfolio_columns\', \'add_new_portfolio_column\');
//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_portfolio_posts_custom_column\',\'show_order_column\');
//make column sortable
function order_column_register_sortable($columns){
$columns[\'menu_order\'] = \'menu_order\';
return $columns;
}
add_filter(\'manage_edit-portfolio_sortable_columns\',\'order_column_register_sortable\');
//Sort post archive by menu_order
add_action( \'pre_get_posts\', \'mpe_portfolio_sort_order\');
function mpe_portfolio_sort_order($query){
if(is_archive() ):
$query->set( \'order\', \'ASC\' );
$query->set( \'orderby\', \'menu_order\' );
endif;
};
我在“portfolio”CPT“supports”数组中加入了“page attributes”