ACF IMG returns ID not URL when in archive.php

I have a WordPress site and have a simple div with a background image in footer.php being called from ACF options field like so:

<div id="footer" style="background-image: url('<?php the_field('footer_background', 'options'); ?>');">

This works perfectly on all my pages and templates. However, when going into a blog category (from the categories widget in the blog page) which is calling archive.php it converts the URL to the image ID and outputs '85' rather than the URL.

Read More

I’ve tried removing all code from archive.php except the header and footer calls incase I had something in there but still no luck. The ACF field is definitely set to ‘url’ hence it works everywhere else.

Any ideas why it converts to ID on the archive.php page?

Related posts

Leave a Reply

2 comments

  1. I was having the same problem, and I found no fix for the plugin, but I solved the situation by making a conditional statement to check if the page was a tag archive and then retrieve the attachment URL by the returned ID.

    if (is_tag()) {
        $imgUrl = wp_get_attachment_url( get_field('image', 'option') );
        } else {
            $img = get_field('image', 'option');
            $imgUrl = $img['url'];
        }
    }
    
  2. I faced the same issue. Mine was because I removed an old field and created it again with the same name on another group.

    What happened is that the old ACF key remained unchanged. This very SO question was mentioned at ACF forum where I found the hint about the problem:

    If an image field is always returning the image ID rather than another value as set in the field setting then this is a symptom of a missing or incorrect field_key in the database

    My old stored values all were wrong, I had to updated them to field_60665667aa3d3 and the URL return started working again.

    database schema