Get_users() с включением И исключениемPhp

Кемеровские программисты php общаются здесь
Гость
Get_users() с включением И исключением

Сообщение Гость »


Я получаю список пользователей, которые находятся в массиве (только идентификаторы), этот массив представляет связи между пользователями. Идея состоит в том, чтобы отобразить 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;
}
The problem is that $members_without_photos is filled with every user out of the $connections array. So that means the include is prioritised above exclude.

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

Вернуться в «Php»