acf_format_value_for_rest()
Format a given field's value for output in the REST API.
Hooks from the function
Returns
Mixed.
Usage
acf_format_value_for_rest( $value, $post_id, $field, $format );
- $value(required)
- .
- $post_id(required)
- .
- $field(required)
- .
- $format(string)
'light'for normal REST API formatting or'standard'to apply ACF's normal field formatting.
Default:'light'
acf_format_value_for_rest() acf format value for rest code ACF 6.0.4
function acf_format_value_for_rest( $value, $post_id, $field, $format = 'light' ) {
if ( $format === 'standard' ) {
$value_formatted = acf_format_value( $value, $post_id, $field );
} else {
$type = acf_get_field_type( $field['type'] );
$value_formatted = $type->format_value_for_rest( $value, $post_id, $field );
}
/**
* Filter the formatted value for a given field.
*
* @param mixed $value_formatted The formatted value.
* @param string|int $post_id The post ID of the current object.
* @param array $field The field array.
* @param mixed $value The raw/unformatted value.
* @param string $format The format applied to the field value.
*/
return apply_filters( 'acf/rest/format_value_for_rest', $value_formatted, $post_id, $field, $value, $format );
}