Support » Plugins » Hacks » Sort users by meta_value_num

  • Been trying some things to output some users and sort by a meta_value_num, but nothing I try works and I can’t find anything online about it.

    This one’s a real challenge.

    $args = array(
        'orderby' => 'meta_value_num',
        'meta_key ' => 'rank',
        'order' => 'DESC',
    // The Query
    $user_query = new WP_User_Query( $args );
    // User Loop
    if ( ! empty( $user_query->results ) ) {
        foreach ( $user_query->results as $user ) {
            echo '<p>' . $user->display_name . '</p>';
    } else {
        echo 'No users found.';

    I can get the meta value for each author on author.php easily enough but I can’t get users to sort by the same meta value.

    [Moderator Note: No bumping. If it’s that urgent, consider hiring someone instead.]

Viewing 1 replies (of 1 total)
  • The codex says you only need to use ‘meta_value’ not ‘meta_value_num’, it could be that.

    Also, for you to sort by a meta key, the meta value needs to exist for all users. If they user does not have a meta value for that key then won’t be returned in the results.

Viewing 1 replies (of 1 total)
  • The topic ‘Sort users by meta_value_num’ is closed to new replies.