I have a field set up that’s located in User. It’s a image field that the User can upload and I’m trying to get the URL so I can output it into an
img src. I’m using other text fields and I’m capable of pulling those just fine.
<?php $user_id = get_query_var( 'author' ) ?>
<?php $clan_member_info = get_userdata($user_id); ?>
<p><?php if(!empty($clan_member_info->psn_id)) echo '<li>' . $clan_member_info->psn_id . '</li>'; ?></p> //Example of me pulling a text field
<?php if(!empty($clan_member_info->cover_photo)) echo '<img src="'.$clan_member_info->cover_photo.'"/>'; ?>
The example of the
psn_id pulls perfectly. The
img returns this
I have the full php file here.
ACF saves the image ID instead of the image URL in the database. Please use the get_field() or the_field() function to get the processed value. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/image/.
Also, please take a look at this page to learn how to get the value from a user: https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/.
I hope this helps 🙂
To print the image URL instead of ID, replace
wp_get_attachment_image( $image, $size );
wp_get_attachment_image_url( $image, $size );
more info here: