Support

Account

Home Forums Front-end Issues Image only showing ID on front end with users

Solved

Image only showing ID on front end with users

  • I am using ACF to create a place where users can upload a profile image on the back end and then have it show up on their posts on the front end.

    I have checked return value to get image url but it keeps pulling in the image ID. I check the source code on the front end and it is just showing the ID. I need the full image url.

    Is this a conflict with the user profile page? I am able to get this to work on other pages no problem.

    Here is how I am calling it in the theme:

    <img src="<?php the_author_meta( 'user_profile_image' ); ?>" />

    Thanks!

  • Hi Moorewebx,

    I think you set your image field to return image ID. There’s two ways you can resolve your problem.

    1. Change return value to image url. See link screenshot for Image Field Settings.

    2. See code below:

    
    <?php echo wp_get_attachment_image( the_author_meta( 'user_profile_image' ) ); ?>

    Thats it, hope I did solve your problem.

  • I did have the return value for image. I also tried your code but am still only getting it to output the image ID. http://s15.postimg.org/q2ycawbwb/Capture.jpg

  • I think your using the wrong function to get your acf field. the_author_meta() is a wordpress function.

    Can you try this.

    <?php echo wp_get_attachment_image( get_field( 'user_profile_image' ) ); ?>

  • So none of those solutions worked but I did find something that did. I used the following code and was able to get the image to finally show up.

                                            <?php
    $publisher_photo = get_the_author_meta('user_profile_image');
    $image_src = wp_get_attachment_image_src($publisher_photo);
    echo '<img class="avatar" src="'. $image_src[0] .'" />';
    ?>

    Thank you for your help with this.

  • I am not sure if your using acf field or wp core because of as far as I know in order to get the value of the acf field you need to use get_field or get_sub_field(if repeater/flexible content).

    Then the above function/method “get_the_author_metat()” is a wordpress function. http://codex.wordpress.org/Function_Reference/get_the_author_meta

    And this code <?php echo wp_get_attachment_image( get_field( 'user_profile_image' ) ); ?> will gives you the whole image object with the correct url.

    Anyways happy for you to get it working.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.