Support » Fixing WordPress » sort users

  • Is there a way to sort by a users first name?

    I’m using Kaf Oseo’s Authors template and have options for user_nicename and display_name, but can’t figure out how to sort this list by first name instead of last name.

Viewing 2 replies - 1 through 2 (of 2 total)
  • any ideas? I’d really like to sort by first name, since I’m using the fields slightly different than traditionally.

    <?php
    $userids = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'first_name' ORDER BY meta_value ASC");
    if ($userids) {
      foreach ( $userids as $userid ) {
        $user = get_userdata( $userid );
        echo '<p>' . $user->first_name . ' ' . $user->last_name . '</p>';
      }
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sort users’ is closed to new replies.