Reputation: 47
I am having trouble displaying an ACF image field. You can see how the field is setup in the attached screenshot. I am using the code below in a template file to display the various fields from the Authors role only:
<?php
$args = array(
'role' => 'Author',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
echo '<ul>';
foreach ( $users as $user ) {
echo $user->display_name . '<br>';
echo $user->title . '<br>';
echo $user->short_bio . '<br>';
echo $user->full_bio . '<br>';
echo $user->author_photo . '<br>';
}
echo '</ul>';
?>
You can see the author_photo field at the end, but it is only returning a number value, not the image url, even the return format of the field is set to Image URL.
Any help would be greatly appreciated.
Upvotes: 1
Views: 2002
Reputation: 9097
Well you need to get the ACF field
for a specific user in a different way than you've already tried.
The id should contain the word ‘user_’ and the user’s ID in the format; "user_{$user_id}".
From ACF Docs
$args = array(
'role' => 'Author',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
echo '<ul>';
foreach ( $users as $user ) {
$author_array_img = get_field('author_photo', 'user_' . $user->ID);
echo $user->display_name . '<br>';
echo $user->title . '<br>';
echo $user->short_bio . '<br>';
echo $user->full_bio . '<br>';
echo $author_array_img['sizes']['thumbnail'] . '<br>';
}
echo '</ul>';
Let me know if you were able to get it to work!
Upvotes: 1