要按元字段排序,需要使用meta\\u键和meta\\u值(或meta\\u值\\u num):
array(
\'meta_key\' => \'sort_order\', //This is the custom field to orderby
\'orderby\' => \'meta_value_num\', //for numerical values
\'role\' => \'Administrator\',
\'fields\' => \'all_with_meta\',
);
但是。。。这可能会在合并之前对结果进行排序。。。所以
您可以使用meta\\u query来获取多个角色,而不是单独的查询:(Get multiple roles with get_users)
(未经测试)
global $wpdb;
$blog_id = get_current_blog_id();
$user_query = new WP_User_Query( array(
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => $wpdb->get_blog_prefix( $blog_id ) . \'capabilities\',
\'value\' => \'author\',
\'compare\' => \'like\'
),
array(
\'key\' => $wpdb->get_blog_prefix( $blog_id ) . \'capabilities\',
\'value\' => \'editor\',
\'compare\' => \'like\'
)
)
//Then add the rest of the query
\'meta_key\' => \'sort_order\', //This is the custom field to orderby
\'orderby\' => \'meta_value_num\', //for numerical values
//\'fields\' => \'all_with_meta\', //which fields to return
) );