Wp_User_Query not sorting by meta key


I’m trying to list users sorted by a meta value. I store a score for each user in their user meta which is just a number but the loop isn’t sorting. I include the score in the loop so that I can see that it’s not being sorted correctly. What am I doing wrong?

 $args = array(
    'meta_key' => 'score',
    'meta_value' => 0,
    'meta_compare' => '>',
    'orderby' => 'meta_value_num',
    'number' => 20
 $suggested_user_query = new WP_User_Query( $args );
 $users = $suggested_user_query->get_results();
 echo '<div id="user_suggest">';
     echo '<ul>';
     foreach ($users as $user) {
         // get all the user's data
         $user_info = get_userdata($user->ID);
         echo '<li>';
     echo '<h3>'.bp_core_get_user_displayname( $user->ID ).'</h3>';
     $score = get_user_meta( $user->ID, 'score', true );
         echo $score;
         echo '</li>';
     echo '</ul>';     
 echo '</div>';
, , Pollux Khafra 11 years 2012-10-29T14:48:36-05:00 0 Answers 85 views 0

Leave an answer