Home › Forums › Front-end Issues › 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">[ <?php echo $user->display_name; ?> ]</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/
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] .'" />';
?>
You must be logged in to reply to this topic.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.