Support

Account

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);