0

I want all of the results to order by meta_value_num, but it's ordering by role first. How do I get them to ignore the role order? Here's my code:

$user_query = new WP_User_Query( array( 
    'meta_key' => 'Group',
    'meta_value' => $atts['bc'],
    'role__in'    => ['role1','role2','role3'],
    'orderby' => 'meta_value meta_value_num',
    'order' => 'ASC',
) );    
$users = $user_query->get_results();

I also tried array_merge but that didn't work either.

  • Note that in WP_Query you specify multiple orderby using an array of items, but the WP_User_Query docs don't list arrays as a possible value. This might be because it hasn't been updated, or because it's not supported, I don't know which – Tom J Nowell Nov 4 '19 at 22:57
  • I'm not quite understanding how you mean. Do you mind posting an example? – Mr Gandy Nov 4 '19 at 23:05
  • 2
    'orderby' => [ 'foo', 'bar', 'etc..' ], WP_Query expects each value to be a string. You don't just pass a single string with each parameter specified by a space, instead to specify an array of items, you use an array. However, the docs for WP_User_Query only say that it accepts a string, which implies it does not support multiple orderby values – Tom J Nowell Nov 4 '19 at 23:44
  • Is there a way around this? Perhaps by hooking with pre_user_query ? – Mr Gandy Nov 5 '19 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.