Home Forums Front-end Issues Image Array


Image Array

  • Hi

    Very new to all this and trying to learn, so bare with me please. I have a site using Shopkeeper theme on WP 4.8.1 and ACF 4.4.11.

    I have created my fields and the fields have appeared on my product pages, but I go to my front end and view the product page, I just get a number displayed not the images?

    Any help would be gratefully appreciated.

    This is the product page

    The two images are located near the bottom on is in the Nutritional accordion and one more below it.


  • Hi @russellknight1979

    What did you choose for the ‘Return value’ for the Images?

    It is dependent on the Return Type how you display the data..

    Have a peek here, and let me know if I could help further.

  • Hi Kieth

    It is set to image ID?



  • Hi Russell,

    Ok, so if you are returning the ID only, then you can use a built in WordPress function to auto-generate the Image HTML for you.

    As a side benefit to doing it this way, the auto-generated code will also be “responsive” – meaning that when someone is viewing your web site, their device will load an image that is appropriate for their device (in terms of file size, etc). Because… WordPress generates multiple-sized images each time you upload.

    At any rate… since you are only storing the Image ID, that’s all you will see if doing:

    echo get_field('image');



    But, since you want the actual image to be generated… you can use the wp_get_attachment_image() WordPress function. If you tell it the Image ID it will display the HTML (i.e. the image will show up). By default, it will just show a ‘thumbnail’. If you want to use a different size, you tell it the size you want (either by name or dimensions). You can learn more about your options here, which makes reference to cropping, etc.

    Below in an example where it specifies a size by name. There are built in sizes in WordPress, plus themes and plugins may also generate different names to create images of different dimensions/orientations. I like to use this plugin so that when I am viewing an image in the WordPress Medial Library, I get to see a list of all available image sizes currently in use.

    Ok, finally, below is the example (assuming again that your field name is ‘image’).
    Note: The example below is pulled direct from this resource. It’s worth a read to wrap your mind around the ACF Image field.

    $image = get_field('image');
    $size = 'full'; // (thumbnail, medium, large, full or custom size)
    if( $image ) {
    	echo wp_get_attachment_image( $image, $size );
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Image Array’ is closed to new replies.