Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Genesis list users by role
<?php
/*
Template Name: Page Contributors
*/
remove_action('genesis_loop','genesis_do_loop');
add_action('genesis_loop','jb_contibutors');
function jb_contibutors() {
echo '<ul>';
//jb_contibutor_loop(array( 'role' => 'administrator', 'fields' => 'all_with_meta' ) );
jb_contibutor_loop(array( 'role' => 'editor', 'fields' => 'all_with_meta' ) );
jb_contibutor_loop(array( 'role' => 'author', 'fields' => 'all_with_meta' ) );
jb_contibutor_loop(array( 'role' => 'contributor', 'fields' => 'all_with_meta' ) );
echo '</ul>';
}
// Get the results
function jb_contibutor_loop($role) {
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query( $role);
$users = $wp_user_query->get_results();
// Check for results
if (!empty($users)) {
// loop trough each author
foreach ($users as $user) {
// get all the user's data
$user_info = get_userdata($user->ID);
$img = get_avatar($user_info->ID, 150);
$url = site_url('/author/');
echo '<li class="aap_user_wrap"><a href="' . $url . $user_info->user_nicename . '">';
echo '<span class="aap_user_name" property=\"v:name\">' . $user_info->first_name . ' ' . $user_info->last_name . '</span>';
echo '<span class="aap_user_img">' . $img . '</span>';
echo '</a></li>';
}
};
};
genesis();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.