Skip to content

Instantly share code, notes, and snippets.

@adamdoe
Last active Aug 23, 2017
Embed
What would you like to do?
Get user of role type and add them into columns using Foundation.
/**
* Author : Doe
* @param string $role_type used for getting type of user.
*/
function get_team_members($role_type) {
$args = array(
'role' => $role_type,
'fields' => 'ID'
);
$team_query = new WP_User_Query( $args );
$team_members = $team_query->get_results();
if ( !empty($team_members)) {
$last = count($team_members);
$count = 0;
$end = '';
// If we have team members count and loop through them...
foreach($team_members as $team_member) {
// Add classes depending on count
if ( $count == 0 || ($count + 1)%3 == 1 ){
$additionalClass = 'large-offset-3';
}
if ( $count == ($last - 1)) {
$end = 'end';
}
echo '<div class="small-12 ' . $additionalClass .' large-2 columns ' . $end .'">';
$member_info = get_userdata($team_member);
$first_name = $member_info->first_name;
$last_name = $member_info->last_name;
$avatar = get_wp_user_avatar($member_info->ID);
$position = get_field('position', $member_info);
echo '<div class="staff-wrapper">';
if( !empty($avatar)) :
echo $avatar;
endif;
if ( !empty($first_name) && !empty($last_name) ) {
echo '<div class="staff-name">' . $first_name . ' ' . $last_name . '</div>';
}
if ( !empty($position) ) {
echo '<div class="staff-position">' . $position . '</div>';
}
echo '</div>';
echo '</div>';
$additionalClass = '';
$count++;
}
}
else { echo 'No Team Members Found'; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment