I’m trying to order the member list by display_name or first name ASC.
http://sim.is/sim/felagatal-sim/
This doesn’t seem to work. Any pointers out there? :/
$users = get_users(array(
'role' => 'sm_flagar',
'orderby' => 'display_name',
'order' => 'ASC',
));
foreach ($users as $user) {
$firstName = get_user_meta($user->ID, 'first_name', true);
$lastName = get_user_meta($user->ID, 'last_name', true);
echo '<li><a href="' . $user->user_url . '">' . $firstName . ' ' . $lastName . '</a></li>' . PHP_EOL;
}
Here is my solution
The original code is not so bad. It just is missing the
meta_key
parameter. Example:Nowadays you can do something like this, as long as you’re trying to sort via the default WP usermeta fields:
remove ‘,’ (without quotes) after ‘ASC’. It will do the trick.
It is working as it is asked to be. If you echo out the display name of each user in the loop, then you will understand what is going on.
replace the ‘echo’ line with:
It is not ordering by first and last name but by “display name”.
To get all users ordered by first name, set the
meta_key
and orderbymeta_value
.EDIT: This appeared to work and SHOULD work. I believe it will work in the next version. But for now, it does not work.
The chosen answer here is the best option I have found until that time:
Ordering users of a specific role by last name