This is probably a typical Dutch issue where you have a last name which can contain multiple words. For example Robin van Persie or Mark de Jong.
Currently I have a list of users ordered by last name, which is the default for get_users
. This works fine most of the time but fails when a user has a last name containing more than one word.
For example Mark de Jong is listed between the 'C' and 'E' because of 'de' Jong. However is should be listed between the 'I' and 'K' as Jong should be seen as the word to sort.
Same with Robin van Persie which get listed between the 'U' and 'W' becasue of 'van' Persie. However it should be listed between the 'O' and 'Q' as Persie should be seen as the word to sort.
Is there a way to create a function for this to solve this issue?
Edit: updated with current code:
$allUsers = get_users('orderby=display_name&order=ASC&exclude=1,4');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(!in_array( 'subscriber', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
usort($users, create_function('$a, $b', 'return strnatcasecmp($a->last_name,
$b->last_name);'));
foreach($users as $user)
{
// Output
Thanks in advance!