Support

Account

Home Forums Bug Reports Image File Type Return Value not working

Solving

Image File Type Return Value not working

  • I have created an Image custom field and no matter what I set it’s “Return Value” to (Image Object, Image URL, or Image ID) it always returns the Image ID.

    I am trying to use the Return Value in another plugin (Slider PRO) to render the image in a jQuery slideshow.

  • Hi @anielsen,

    Are you using get_field to fetch the image?

    Please try a var_dump(get_field('image-field-name'))

    Is it dumping different things when you change the return value?

    Cheers

  • I’m trying to use the return value in a plugin called Slider PRO, you can see my setup here: http://colbyblogs.org/wptest/custom-post-types/

  • Hi @anielsen

    As asked above, Are you using get_field to fetch the image?

    What code are you using to display the image in your template?

  • I’m not sure what I’m doing wrong: http://colbyblogs.org/wptest/custom-post-types/shortcode/

    On this page I’m using a plugin called CSS & Javascript Toolbox to inject PHP code on my page, if you look at the source code the img tag isn’t working right with the code I took from your help pages:

    <img src="<?php the_field('field_name'); ?>" alt="" />

  • Hi @anielsen

    What is the return type of your image field?
    ID, ARRAY or URL?

  • I’ve tried all three, but it is currently Image URL.

  • I decided to create a child theme so I could inject the PHP directly into the page without having to rely on a plugin. As you can see on the page linked below, the same “bool(false)” happens with the code you provided in the page.php file of the theme.

    http://colbyblogs.org/wptest/custom-post-types/

    Any idea why this would happen?

  • Hi @anielsen

    Looking at the source code, I can see that the image has a src of 12. This means that the value returned is the image ID.

    Perhaps you are not correctly using the get_field` function to retrieve the formatted value?

    Can you post the code you are using to render the slider?

    Thanks
    E

  • I am using a plugin called Slider PRO to render the slider.

    The other two ACF fields I have (Medium and Artist) work fine.

    I have the following code in my page.php file and it only returns “bool(false)”.
    <?php var_dump(get_field('artwork_image')) ?>

  • Hi @anielsen

    What type of field is artwork_image?
    How do you handle multiple images?
    Are you sub fields within a repeater field?
    What code are you using to render the slider?
    Did you place the var_dump code within your loop (alongside functions like the_content)?

    Thanks
    E

  • The artwork_image field is an Image field set to return the Image URL.

    I have the field assigned to a custom post type.

    I’m not sure what “sub fields” and “repeater field” mean.

    I’m using a plugin called Slider PRO to render the slider. It allows for custom fields to be used to generate content in the slider (images, captions, etc) and my Text fields work for the captions (see “media” and “artist”) but the Image field only returns the Image ID, never the URL.

    I accidentally placed the var_dump outside the loop, but I have since corrected that and still get bool(false).

  • Hi @anielsen

    The image field will always save it’s data as the attachment ID, then when using the get_field function, the value will be modified based on the return value setting.

    This explains why your slider plugin is not able to read in the image.
    Perhaps you can ask the developer of the slider plugin how you can make this compatible with ACF when ACF save’s it’s image custom field data as the attachment ID, not the attachment URL.

    Thanks
    E

  • When using get_field() or the_field() and the Image ID is returned instead of the expected return value, this is a sign that acf_add_local_field_group() was not run. Therefore ACF is pulling the raw value from the database but has no way to determine in which format you want it.

    To resolve the issue, ensure that acf_add_local_field_group() is run from the init hook, not one of the admin_* hooks.

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

The topic ‘Image File Type Return Value not working’ is closed to new replies.