Я получаю список пользователей, которые находятся в массиве (только идентификаторы), этот массив представляет связи между пользователями. Идея состоит в том, чтобы отобразить X пользователей и скрыть остальных, поэтому приоритетом являются пользователи с установленными аватарами.
Вот что у меня работает неправильно:
Код: Выделить всё
// Get all connection id's with avatars
$members_with_photos = get_users(array('meta_key' => 'profile_avatar', 'include' => $connections));
// Shuffle them
shuffle($members_with_photos);
// Add the the all_members list
foreach($members_with_photos as $member_with_photo){
$all_members[] = $member_with_photo->ID;
}
// Get all connection id's without avatars
$members_without_photos = get_users(array('exclude' => $all_members, 'include' => $connections));
// Shuffle them
shuffle($members_without_photos);
// Also add them to the list
foreach($members_without_photos as $member_without_photos){
$all_members[] = $member_without_photos->ID;
}
What needs to happen is that get_users() needs to look for users from connections, but exclude the ones that already are found (with avatars) so that the users without avatars will appear last in the $all_members array.
The way I fix it now is use array_unique() on the $all_members array after, but I think that is more of a dirty fix. Can someone point me in the right direction here?
Источник: https://stackoverflow.com/questions/164 ... nd-exclude
Мобильная версия