0

i have created user vote that can vote users or author of posts. so for example have 4 users which looks:

  1. user --- ID=1 --- META KEY='_thumbs_rating_up' --- META VALUE='13'

  2. user --- ID=2 --- META KEY='_thumbs_rating_up' --- META VALUE='17'

  3. user --- ID=3 --- META KEY='_thumbs_rating_up' --- META VALUE='8'

  4. user --- ID=4 --- META KEY='_thumbs_rating_up' --- META VALUE='241'

So i must order these users by user meta key and meta value from heighest to lowwer. So i have these code now but order is not correct:

<?php
$args = array( 
'role' => 'Seller',
'meta_key' => '_thumbs_rating_up',
'orderby' => 'meta_value_num'
);

// The Query
$user_query = new WP_User_Query( $args );

// User Loop
if ( ! empty( $user_query->results ) ) {
    foreach ( $user_query->results as $user ) {

        echo '<p>' . get_avatar( $user->ID, 32 ) . '</p>';
        echo '<p>' . get_user_meta($user->ID, '_thumbs_rating_up', true). '</p>';
        echo '<p>' . $user->display_name . '</p>';
    }
} else {
    echo 'No users found.';
}
?>

what i do wrong or simply can not order my custom meta key??????

0

The QA that you have linked to is related but not needed here.

meta_value_num is still not part of the user_query core and so, your meta_value_num parameter has no effect on the query.

Just use meta_value as described on codex and you'll get what you want.

  • I also try with only meta_value and not work... – Toni Ojsteršek Mar 2 '15 at 13:04
  • ok now work i dont write meta_value ...sory and thnx for help – Toni Ojsteršek Mar 2 '15 at 16:23
0

you can missing the ORDER = DESC. Try this

<?php 
$args = array( 
'role' => 'Seller',
'meta_key' => '_thumbs_rating_up',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.