Support

Account

Home Forums Front-end Issues Display all users/authors in template

Solved

Display all users/authors in template

  • I’m trying to display all my authors/users in a custom page template. I’m using the following code to display their profile photos that grab from an acf image field called author_header. I put the users in an unordered lists by the following.

    <div class="author">
    <ul>
    <li>                 
    <?php
    $publisher_photo = get_the_author_meta('author_header');
    $image_src = wp_get_attachment_image_src($publisher_photo);
    echo '<img src="'. $image_src[0] .'" />';
    ?>
    </li>
    </ul>
    </div>
    

    The problem I’m facing is that all the users get my profile photo. I want to be able to just grab the ones that they uploaded to the author_header field. I do have all of their names correctly displaying in the unordered list by the following.
    <h2 class="authorName">[&nbsp;<?php echo $user->display_name; ?>&nbsp;]</h2>. Thank you!

  • You should be using get_field() and you need to supply the post_id to get the value from.

    For users the correct $post_id value is `”user_{$user_id}”

    see the “Get a value from other places” section on this page https://www.advancedcustomfields.com/resources/get_field/

  • This reply has been marked as private.
  • Thanks for the info! I think I may still be doing something wrong, but here is what I have so far

    <?php
    $field_name = "author_header";
    $post_id = "user_{$user_id}"; 
    $publisher_photo = get_field($field_name, $post_id);
    $image_src = wp_get_attachment_image_src($publisher_photo);
    echo '<img class="grayscale" src="'. $image_src[0] .'" />';
    ?>

    Any advise? thanks!

    Here is the working solution

    <?php
    $user_id = $user->ID;
    $publisher_photo = get_the_author_meta('author_header', $user_id);
    $image_src = wp_get_attachment_image_src($publisher_photo);
    echo '<img src="'. $image_src[0] .'" />';
    ?>
  • You’re using get_the_author_meta

    If you used get field it would need to be

    
    <?php
    $user_id = 'user_'.$user->ID;
    $publisher_photo = get_field('author_header', $user_id);
    $image_src = wp_get_attachment_image_src($publisher_photo);
    echo '<img src="'. $image_src[0] .'" />';
    ?>
    
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Display all users/authors in template’ is closed to new replies.