Reputation: 573
I'm trying to display all my authors/users in a custom page template using advanced custom fields. 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 have also tried this revised code but the img src doesn't show up.
<?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 src="'. $image_src[0] .'" />';
?>
I do have all of their names correctly displaying in the unordered list by the following.
<h2 class="authorName">[ <?php echo $user->display_name; ?> ]</h2>
Upvotes: 1
Views: 239
Reputation: 1916
You should add the user ID in get_the_author_meta
like this:
$user_id = $user->ID;
$publisher_photo = get_the_author_meta('author_header', $user_id);
Please make sure that you will add this code in the loop, so user_id will be different for different user every time.
Regards, Stanimir
Upvotes: 2