• Resolved aspsa

    (@aspsa)


    Greetings and Happy New Year.

    I have the Advanced Custom Fields WordPress plugin free version, version number 5.9.3 and created a custom field group. It contains a “Tab” type custom field labeled “Overview and has a “Group” field within it labeled “Basics”. “Basics” group contains “Tab” field labeled “Images”. Inside the “Images” sub field are three “Image” type custom fields, each returning an “Image Array”.

    For example, the first image field has the field name “product_image_01”. All of its remaining field descriptors are at their default values. The ACF custom field group itself is assigned to a custom post type for which I created a custom post type template. Here is the code in question for the custom post type template.

    <?php
    $product_image_01 = get_field("product_image_01");
    var_dump($product_image_01);
    ?>
    <img src="<?php $product_image_01; ?>" />

    The “var_dump” function returns NULL, even though I assigned an image to the custom post that is associated with the custom post type to which the ACF custom field group is assigned. I received a NULL return despite the image return type (array, url, id).

    I also separately tried the following as a test, although I do not see why it would be necessary to associate a product image with a WP user:

    <?php
    $author_id = get_the_author_meta('ID');
    $author_pi_01 = get_field('product_image_01', 'user_' . $author_id);
    echo $author_pi_01;
    ?>

    This did not work either. In fact, it returned no response at all.

    Thus far, I was able successfully to return data from a variety of other ACF custom field types (text, url, text area, range, select, number) defined elsewhere under the “Basics” group. I only have a problem with the ACF ‘Image” field type.

    I would appreciate guidance on returning an image result in this scenario. Thank you.

    • This topic was modified 4 years, 2 months ago by aspsa.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter aspsa

    (@aspsa)

    Minor update:

    <img src="<?php $product_image_01; ?>" />

    …should be…

    <img src="<?php $product_image_01['url']; ?>" />

    Nevertheless, it still does not work.

    Thread Starter aspsa

    (@aspsa)

    I resolved the issue by changing

    <?php
    $product_image_01 = get_field("product_image_01");
    ?>
    <img src="<?php $product_image_01; ?>" />

    …to…

    <?php
    $product_image_01 = get_field("group_product_image_01");
    ?>
    <img src="<?php $product_image_01; ?>" />

    I discovered this by revealing the custom post’s metadata as follows:

    <pre><?php print_r(get_post_custom($product_owner_link); ?></pre>

    The PHP $product_owner_link variable references an Advanced Custom Field (ACF) relational field which points to the custom post in question having the product image that I want to display. For usability purposes, I leveraged ACF’s group and tab features. In the way that I nested the product image custom field, ACF prepended “group_” to the existing “product_image_01” custom field’s field name.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ACF ‘Image’ Field Returns NULL’ is closed to new replies.