Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>';
share|improve this question
    
Why not just order by meta_value_num, why would you compare each one to 0? –  Wyck Oct 29 '12 at 21:35
    
Doest work that way either but I need to leave out 0 scored and negatives –  Pollux Khafra Oct 29 '12 at 22:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.