Let's say hypothetically I have this information listed on each users profile:
UserA (list) = dog, cat, sheep, bird, duck
UserB (list) = zebra, lion, cheetah, leopard
UserC (list) = alligator, lizard, frog, turtle
and I have this function:
foreach($users as $user){
$user_list = $user->list;
$user_list_array = explode(', ', $user_list);
foreach($user_list_array as $user_list_item){
}
}
}
This is where I'm stumped... How do I combine all the lists into one big comma separated list and explode that full list into one array that I can then use?
EDIT: Here are the exact sample lists I'm testing with and the results I'm getting with the following code:
THE LISTS:
ListA: Singing, Rapping, Dancing, Comical Skits, Cooking, Cleaning, Shoe-Tying, Hop on No Legs
ListB: Wine Tasting, Hospitality, Business Management, Financial Planning, Business Marketing, Professional Driving
THE CODE:
<?php
$roles = array('employee', 'administrator');
/* Loop through users to search for the admin and employee users. */
foreach( $roles as $role ) {
$this_role = "'[[:<:]]".$role."[[:>:]]'";
$query = "SELECT * FROM $wpdb->users WHERE ID = ANY (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value RLIKE $this_role) ORDER BY user_nicename ASC LIMIT 10000";
$users = $wpdb->get_results($query);
if ($users){
$output = array();
foreach($users as $user){
$curuser = get_userdata($user->ID);
$user_list = $curuser->skills;
$user_list_array = explode(', ', $user_list);
foreach($user_list_array as $user_list_item){
$output[] = $user_list_item;
}
}
echo implode(', ', $output);
}
}?>
THE RESULT:
Singing, Rapping, Dancing, Comical Skits, Cooking, Cleaning, Shoe-Tying, Hop on No Legs, , , , , , Wine Tasting, Hospitality, Business Management, Financial Planning, Business Marketing, Professional Driving
$users, you just need to check if$user_listis non-empty.