Last active
August 29, 2015 14:13
-
-
Save calliaweb/53ec796352380f48e986 to your computer and use it in GitHub Desktop.
Sort users by last name and then first name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nm2_people_page() { | |
// Get all user IDs | |
$args = array( | |
'fields' => 'ID', | |
); | |
$pids = get_users( $args ); | |
// If we have people get their first names and last names | |
if( $pids ) { | |
foreach( $pids as $pid ) { | |
$lastnames[] = get_user_meta( $pid, 'last_name', true); | |
$firstnames[] = get_user_meta( $pid, 'first_name', true); | |
} | |
// Sort arrays by lastname, then firstname then ID | |
array_multisort( $lastnames, $firstnames, $pids ); | |
// Print out the results | |
foreach( $pids as $key=>$pid ) { | |
echo $lastnames[ $key ] . ' ' . $firstnames[ $key ] . ' ' . $pid . '<br />'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment