Home › Forums › Bug Reports › Image Format in Rest API is always ID › Reply To: Image Format in Rest API is always ID
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);
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.