You don’t actually need to call get_userdata()
, all the data you need should be in the relational field array:
EDIT: Add post ID and User ID to calls to get_field()
.
<?php
$posts = get_sub_field('who_to_show');
if( $posts ): ?>
<?php foreach( $posts as $post):
setup_postdata($post);
$user_info = get_field( 'relational_user_field', $post->ID );
$image = get_the_field('author_image', 'user_'.$user_info->ID );
$role = get_the_field('role', 'user_'.$user_info->ID );
?>
<h3><?php echo $user_info->user_nicename; ?></h3>
<img src="https://wordpress.stackexchange.com/questions/312929/<?php echo $image["url']; ?>" alt="https://wordpress.stackexchange.com/questions/312929/<?php echo $image["alt']; ?>" />
<?php endforeach;
endif;
wp_reset_postdata();
endif; ?>
Obviously swap 'relational_user_field'
for your actual field name.
The data returned in the user array is the same as the return values in the_author_meta