Support

Account

Home Forums ACF PRO Display multiple selected users NOT WORKING!. Reply To: Display multiple selected users NOT WORKING!.

  • 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; ?>