Skip to content

Instantly share code, notes, and snippets.

@calliaweb
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calliaweb/53ec796352380f48e986 to your computer and use it in GitHub Desktop.
Save calliaweb/53ec796352380f48e986 to your computer and use it in GitHub Desktop.
Sort users by last name and then first name
<?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