Retrieving Advanced Custom Field within Shortcode Function [closed]

“You have to explicitly pass post ID as the 2nd argument.” – Milo

In the Advanced Custom Fields plugin file, plugins/advanced-custom-fields/core/api.php, get_fields has a default $post_id of false, and calls on get_field_objects, which seems to run specific calls to $wpdb->get_col($wpdb->prepare, depending on what $post_id contains (is_numeric?, strpos('user_')), so I guess depending on the environment of the loop you’re calling it from it will return different results, unless $post->ID is specified.

So as specified by @Milo above:

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

Will get us the image object.

I think get_the_title($post->ID) is native WordPress and probably works similarly.

Running get_the_excerpt($post->ID) returns a warning:

get_the_excerpt was called with an argument that is deprecated since version 2.3 with no alternative available., but just running get_the_excerpt() is returning the post excerpt as desired.