WordPress.org

Ready to get started?Download WordPress

Forums

sort users (3 posts)

  1. csleh
    Member
    Posted 5 years ago #

    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.

  2. csleh
    Member
    Posted 4 years ago #

    any ideas? I'd really like to sort by first name, since I'm using the fields slightly different than traditionally.

  3. MichaelH
    Member
    Posted 4 years ago #

    <?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>';
      }
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic