Home › Forums › General Issues › Display Name and role using a user field › Reply To: Display Name and role using a user field
If $user['display_name']
works just fine, then perhaps this will to do the trick. At least it should:
<h3>Asistentes</h3>
<div>
<?php $users = get_field('asistentes'); ?>
<ul>
<?php
foreach ($users as $user):
$roles = new WP_User( $user['ID'] ) ?? false ;
$roles = is_object( $roles ) ? $roles->roles : [] ;
?>
<li>
<p><?php echo $user['display_name'];
echo 'User roles: ' . implode(', ', $roles) . "\n";?></p>
</li>
<?php endforeach; ?>
</div>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.