I'm having trouble getting consistent results from a WP_User_Query when ordering by multiple meta values.
There is a meta field that contains a serialized list of IDs, and I need to display users with a certain ID (72) first. These users need to be alphabetized by last name. The following users without this ID need to be alphabetized by last name as well.
The query works fine if I only look for users with the ID 72 and sort by last name. When I use the query below however, I get inconsistent last name sorting results. The ID 72 users always show up first, but certain users are inexplicably out of order.
Here's the gist of my query:
$users = new WP_User_Query( array(
'meta_query' => array(
'relation' => 'AND',
'lastname' => array(
'key' => 'last_name',
'compare' => 'EXISTS',
'type' => 'CHAR',
),
'list' => array(
'distribution_list' => array(
'key' => 'distribution_list',
'value' => '"72"',
'compare' => 'LIKE'
),
'distribution_list2' => array(
'key' => 'distribution_list',
'value' => '"72"',
'compare' => 'NOT LIKE'
),
'relation' => 'OR',
),
)
'orderby' => array(
'distribution_list' => 'ASC',
'last_name' => 'ASC',
),
) );
orderby
should be outsidemeta_query
.