List Users by Role (with ACF and User Profile Image)

If your website has several News / Blog contributors, you can display a list of Authors by role and link back to their individual landing pages (author.php).

<div id="contributors">
	
	<?php $args = array(
		'role' => 'contributor', // accepts all user roles
		'orderby' => 'post_count',
		'order' => 'DESC',
	); 
	
	$contributors = get_users($args);
	
	foreach ($contributors as $user) : setup_postdata($user); ?>
		
		<a href="<?php echo get_author_posts_url( $user->ID ); ?>">
			<div class="contributor">
				<div class="author_img">
					<?php // User Profile Picture called 
						mt_profile_img( $user->ID, array(
					        'size' => 'medium',
					        'attr' => array( 'alt' => 'Alternative Text' ),
					        'echo' => true )
					    );
					?>
				</div>
				<div class="content">
					<h2><?php echo $user->display_name; ?></h2>
					<h3><?php // get ACF custom fields from user profile by user ID
                                        the_field('title', 'user_'. $user->ID); ?></h3>
				</div>
			</div>
		</a>
		
	<?php endforeach; wp_reset_postdata(); ?>
	
</div><!-- #contributors -->

References:

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.