Home › Forums › Front-end Issues › Display user field value in template
I want to create a page with all the user profiles, but i only want to display the images they defined in the Advanced Custom Fields on their user profiles.
I tried to do something like this:
<?php if (is_page(9)){ ?>
<ul class="profilePictures">
<?php
$blogusers = get_users('orderby=nicename&role=subscriber');
foreach ($blogusers as $user) {
echo '<li><div class="image_wrapper"><img class="profile1" src="
[acf field="profilbild"]
"/></div><img class="profile2 hoverShow" src="
[acf field="funbild"]
"/><div class="imageOverlay"><p>
[acf field="nickname"]
</p></div></li>';
}
?>
</ul>
<?php } ?>
But it fails at locationg the right user, i think. I’t simply doesn’t know from which user to get the value from.
What would be a solution for this?
Hi @flowbob
I think you are confused as to how to output a value in ACF. Can you please read the getting started docs and get_field / the_field.
You can’t use a shortcode in PHP like you have.
If you are using ACF 4.3.3 or higher, you can pass in the $user object to the get_field function to load the value like so:
$image = get_field('profilbild', $user);
Thanks
E
Thank you!
This was the solution i’ve come up with now:
$image1 = get_field('profilbild', $user);
$image2 = get_field('funbild', $user);
$name = get_field('nickname', $user);
echo '<li><div class="image_wrapper"><img class="profile1" src="';
echo $image1['url'];
echo '"/></div><img class="profile2 hoverShow" src="';
echo $image2['url'];
echo '"/><div class="imageOverlay"><p>';
echo "$name";
echo '</p></div></li>';
Maybe this helps anyone reading this later 😉
I’m trying to do something similar. The user is able to upload their photos from within their profile area of the admin (user-edit.php), and then I add your code (and others I found elsewhere) to author.php, but no pictures ever show up. I’ve substitued your field names with my own to no avail. Any help would be appreciated.
maybe give us some code you use?
i got further problems with this project and ended up creating custom posts for every user, which made it much easier.
The topic ‘Display user field value in template’ 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.