WordPress后台文章列表添加排序选项

下面的代码可以在 WordPress 后台文章列表添加排序选项下拉筛选框,支持多种方式排序。

add_action('restrict_manage_posts', function($post_type){
global $wp_list_table;

list($columns, $hidden, $sortable_columns, $primary) = $wp_list_table->get_column_info();

foreach($sortable_columns as $sortable_column => $data){
if(isset($columns[$sortable_column])){
$orderby_options[$sortable_column] = $columns[$sortable_column];
}
}

echo wpjam_get_field_html([
'title' =>'',
'key' =>'orderby',
'type' =>'select',
'value' =>$_REQUEST['orderby'] ?? '',
'options' =>$orderby_options
]);

echo wpjam_get_field_html([
'title' =>'',
'key' =>'order',
'type' =>'select',
'value' =>$_REQUEST['order'] ?? 'DESC',
'options' =>['desc'=>'降序','asc'=>'升序']
]);
});
2
封面图

评论0

请先

没有账号? 注册  忘记密码?

社交账号快速登录