Support

Account

Home Forums Backend Issues (wp-admin) Image filter for restapi Reply To: Image filter for restapi

  • You need to do either or both of the following

    First if you have not set ACF to return the image ID for the image field then you need to change this. If you have it set to return an anything other than the ID then ACF may have already formatted the value, in this case $image = wp_get_attachment_image_src($value, 'full'); is likely generating an error. If you can’t change the return format then you will need to get the value without formatting instead of depending on the passed $value. $value = get_field($field['key'], $post_id, false);

    Second you need to set the priority > 10. ACF has a built in filter for acf/format_value/type=image on priority 10. If this filter runs after your filter it will ignore any formatting you’ve done in your filter and do its normal formatting, whatever that is. If the filter runs before your filter and you have set ACF to return anything other and the ID it may have already done the formatting. See the first explanation. There is no guarantee which filter will run first when both have the same priority.

    format_value does not need a special return format, ACF will return whatever you return from the filter as long as it runs after the ACF filter.