Now I have followed the steps below.
https://www.advancedcustomfields.com/resources/user/
But this thing doesn’t work
1. The nickname shown is not a link to the author.
2. Avatar do not show
3. I would like to add biographical information as well. What are the guidelines?
My setting in acf.
Post the code you’re using. You mentioned that you followed the steps in the documentation, but perhaps you have something wrong the we can identify.
I use this code Did not edit anything, because the field uses the same name.
<?php
$users = get_field("volunteers");
if( $users ): ?>
<ul class="volunteers-list">
<?php foreach( $users as $user ): ?>
<li>
<img src="<?php echo esc_attr( get_avatar($user->ID) ); ?>" alt="author-avatar" />
<a href="<?php echo esc_attr($user->user_url); ?>"><?php echo $user->display_name; ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
It looks like you may have found an issue that needs to be updated in ACF in regards to the avatar image. I tried this code as well and got the same results that you did.
Here’s why it wasn’t working:
– The code is using get_avatar
which returns the avatar, but in an <img>
element. So using that within the src
attribute of another <img>
is the issue here.
– Simply change ‘get_avatar’ to get_avatar_url
which will only return the image’s source. See my example below.
– The user’s link isn’t working because that needs to be manually entered on the User’s profile. Go to a User’s profile in the admin and you will see a field named “Website”, this is what will be returned when using $user->user_url
from the example code.
– I’ve added a conditional to my code example below, that will only wrap the User’s name in an <a>
tag, if they have a $user->user_url
stored on their profile. Otherwise it will just print out their name as text.
Here’s my example of the code, modified to fix the issue:
<?php
$users = get_field("volunteers");
if( $users ): ?>
<ul class="volunteers-list">
<?php foreach( $users as $user ): ?>
<li>
<img src="<?php echo esc_attr(get_avatar_url($user->ID)); ?>" alt="author-avatar"/>
<?php if($user->user_url) : ?>
<a href="<?php echo esc_attr($user->user_url); ?>"><?php echo $user->display_name; ?></a>
<?php
else :
echo $user->display_name;
endif;
?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Mystery solved! But my biography It’s not showing yet. Can you recommend me?
The problem has been resolved.
<?php
if( have_rows('authors') ): while ( have_rows('authors') ) : the_row();
?>
<div class="entry-author ">
<?php $author_id = get_sub_field('user')['ID']; ?>
<div class="pic">
<a rel="author">
<img alt='' src='<?php echo get_field('image', 'user_' . $author_id )['url']; ?>'
class='avatar avatar-160 photo' height='160' width='160' />
</a>
</div>
<div class="info">
<h2 class="name"> <a href="<?php echo get_author_posts_url($author_id, $author_nicename) ?>"
rel="author"><?php echo get_sub_field('user')['display_name']; ?></a></h2>
<div class="desc"><?php echo get_field('role', 'user_' . $author_id); ?></div>
<div class="desc"><?php echo get_field('bio', 'user_' . $author_id); ?></div>
</div>
</div>
<?php endwhile; endif; ?>
<?php endif; ?>
The topic ‘Display multiple selected users NOT WORKING!.’ is closed to new replies.
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.