I'm trying to display user info including custom fields determined by an ACF relational user field, and all contained within a flexible content field.
EDIT Updated code following answers / comments, but still can't get anything to output - all my variables are empty.
The flexible content part is fine, and I'm just including it for context.
I have hit a brick wall with getting the related user info out though.
Within my flexible content layout, I have:
Field Type: User
Select multiple values?: Yes
Return format: User Array
Then in my template I have (most HTML Stripped out):
(role
and author_image
are ACF fields in the user entry).
<?php
$posts = get_sub_field('who_to_show');
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
$user_info = get_userdata($post);
$image = get_field('author_image', 'user_' . $user_info->post_author );
$role = get_field('role', 'user_' . $user_info->post_author );
?>
<p><?php echo $role; ?></p>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach;
endif;
wp_reset_postdata(); ?>
I also tried:
<?php
$posts = get_sub_field('who_to_show');
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
$image = get_field('author_image');
$role = get_field('role');
?>
<p><?php echo $role; ?></p>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endforeach;
endif;
wp_reset_postdata(); ?>
And still my variables are empty.
It's worth noting the image field Return Value is set to "Image Array" in ACF.
Any pointers in the right direction appreciated.
'author_image'
from$user_info
, right?