Support » Plugin: Advanced Custom Fields » Image field not returning URL in archive loop following update to 5.7.8

  • Both get_field() and the_field() are failing to return the File URL when used within an archive loop following the most recent update. They’re just returning the ID instead.

    This is limited to posts within an archive loop – standalone pages where the field is requested still return the File URL as expected (and as specified in the field settings)


    Archive for category:
    – broken images within the white boxes above supplier name

    Single listing:
    – logo displays successfully above supplier name

    Both use same code snippet to display.

    I’ve tried also specifying the post ID within the loop, and also tried the alternative display method of grabbing the array and selecting the URL element. Both just display the ID still.

    Any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m experiencing the same problem. It would be nice if the developers fixed the bug in the next update.

    In the meantime, we might have to program a workaround to grab the src URL.

    If you have a fix for this issue please post it here for future reference, I am having exactly the same problem.

    Meanwhile, rolling back to version 4…

    My lightboxes on Within functions.php:

    /* hack to compensate for Custom Field plugin bug (Jan 2019) where image field returns ID instead of img src URL
     used in homepage, tag.php, and index.php */
    function checkforimgurl($supposedurl) {
    	// is .jpg or .gif in src URL?
    	if (strpos($supposedurl, '.jpg') !== false) {
    		return $supposedurl;
    	} elseif (strpos($supposedurl, '.gif') !== false) {
    		return $supposedurl;				
    	} else { // $supposedurl is an ID, so get the real src URL
    		$large_url = wp_get_attachment_image_src($supposedurl,'full', true);
    		$largeCover = $large_url[0];
    		return $largeCover;				

    Then on the calling page:

    // lightbox for cover enlargment, or link to client if a website
    if ($newestcoverupload = get_post_meta($post->ID, 'newest-coverupload', true)) {	
    	echo '<a class="group1" href="' . $newestcoverupload . '" title=" ">';
    elseif ($largeimage = get_post_meta($post->ID, 'large_image', true)) {	
    	if (function_exists(checkforimgurl)) {
    		$largeimage = checkforimgurl($largeimage);
    	echo '<a class="group1" href="' . $largeimage . '" title=" ">';
    elseif (isset($newestlink)) {
    	echo '<a href="'.$newestlink.'" target="_blank">';

    * This was to fix my lightboxes . . .

    I don’t know why the text editor cut off the beginning of my message.

    Thank you very much for the quick response and a good fix. You saved my day.

    I adapted the code to my needs and indeed I managed to get an url from an existing post ID.

    For anybody needing explanations for the code above, the key is to get the url from ID using wp_get_attachment_image_src($small_image,’full’, true)[0];
    Use conditions to make sure you’re passing an ID and not an url. In my case, the ACF get_field returns an ID, for an image, only in category pages.

    Until the plug in is fixed by the developer, this will work.

    Glad I could help. I probably gave you more code than you needed.

    Thread Starter iangeek


    Apologies for leaving this thread cold (rude of me) – good fix @mwarner1 . I ended up doing much the same as a workaround. Still don’t really know why it happened, but glad to know I wasn’t the only one.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Image field not returning URL in archive loop following update to 5.7.8’ is closed to new replies.