Support

Home Forums Add-ons Gallery Field Gallery field return images IDs

Solving

Gallery field return images IDs

  • Hello,
    I bought ACF PRO to use the gallery field but I have a problem with it.
    The field return an array of string (probably image’s ID) when i var_dump it.
    Obviously I would like to get at least url to display it, like in the documentation.

    <?php $images = get_field('img_event', $post->ID);
    var_dump($images);?>

    array(2) { [0]=> string(3) "360" [1]=> string(3) "292" }

    I have already installed my website on an other host but same thing.

    What is wrong ?

    Thank you

  • What do you have the field set to return, check your field settings.

  • I have no sensitive settings about the field (like the image field where you can chose how the field is displayed : array, url or id).

    I can just chose label, name, type (gallery), instructions, required, minimum and maximum selection, insert, library, restriction on size image, allowed file type, conditional logic and wrapper attribut.

    I don’t see what can change how the field is returned.

  • That’s strange, could have swore there was a setting on that field at one time. Been a while since I used an image field I guess. If the gallery field is only returning IDs this is usually caused by something else interfering. The question comes up here often, like this one https://support.advancedcustomfields.com/forums/topic/image-field-on-term-returning-id-instead-of-array/

    You’re going to need to narrow down where the interference might be coming from by disabling other plugins and possibly switching themes.

  • I have the same issue.
    I’ve tried on default ‘Twenty Seventeen’ and ‘Twenty Fifteen’ – the same.
    It seems that this settings just missing for gallery …

  • yes, this setting missing because in fact does not needs.
    Gallery returns array, if needs to get image IDs needs to use [‘ID’] as parameter, i.e. for example:

    <?php
       $images = get_field('gallery_field'); //gallery field
       foreach( $images as $img ):
       $img_srcset = wp_get_attachment_image_srcset($img['ID']); // return Image ID for each in gallery
    ?>
  • There is no setting for the gallery. It returns an array of image arrays. If you want to only return an array of IDs you can do

    
    $gallery = get_field('my_gallery_field', false, false);
    

    the 3rd parameter tells ACF not to format the value and this causes it to return just the list of IDs

    the 2nd parameter is the post ID, setting it to false just means the current post

    If you are trying to get the array of image arrays and acf is only returning the array of IDs anyway, this is almost always caused by a pre_get_posts filter that is incorrectly filtering the queries that ACF does to get the images. Usually because there is not sufficient logic to rule out these queries before making modifications.

  • sorry, yes, mistake.
    I meant Images IDs of gallery.

  • I had this problem too when registering the gallery field programatically.
    When I called :

    get_field('gallery_field_name',$post->ID)

    I got ID’s instead of image arrays.

    The Problem was, that I only registered the fields on the dashboard through checking for:

    is_admin()

    before calling:

    acf_add_local_field_group();

  • great

  • This reply has been marked as private.
Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.