Home › Forums › Bug Reports › Image Format in Rest API is always ID
Updated to 5.9.1 and now all images are only output as ID even though it is set to be URLs.
Hey, I’ve got the same issue. As it breaks my clients site completely, it’s quite urgent.
Thanks for having a look,
Tobi
Hey @shortee, I just found a thread from late 2021 which explains the fix for this:
https://support.advancedcustomfields.com/forums/topic/acf-rest-api-image-only-shows-attachment-id/
Add ?acf_format=standard to your API call. Hope that fixed your issue too.
Cheers,
Tobi
Very interesting. This also solves my problem, but as the return value for all fields change it creates new problems with other fields.
Is it possible to change the output format for a single field?
Another solution is to use acf/rest/format_value_for_rest/type=image filter
function custom_acf_rest_api_image_format($value, $post_id, $field) {
// Get the full image object from the ID using wp_get_attachment_image_src()
$image = wp_get_attachment_image_src($value, 'full');
// Return an array with the image URL and other metadata
return array(
'url' => $image[0],
'width' => $image[1],
'height' => $image[2],
'alt' => get_post_meta($value, '_wp_attachment_image_alt', true)
);
}
// Hook the filter function to the acf/rest/format_value_for_rest/type=image filter
add_filter('acf/rest/format_value_for_rest/type=image', 'custom_acf_rest_api_image_format', 10, 3);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.