acf_field_select::format_value_single
Formats the value when the select is not a multi-select.
Method of the class: acf_field_select{}
No Hooks.
Returns
mixed.
Usage
$acf_field_select = new acf_field_select(); $acf_field_select->format_value_single( $value, $post_id, $field );
- $value(mixed) (required)
- The value to format.
- $post_id(int|string) (required)
- The post_id from which the value was loaded.
- $field(array) (required)
- The field array holding all the field options.
Changelog
| Since 3.6 | Introduced. |
acf_field_select::format_value_single() acf field select::format value single code ACF 6.8.8
public function format_value_single( $value, $post_id, $field ) {
// Bail early if is empty.
if ( acf_is_empty( $value ) ) {
return $value;
}
$label = acf_maybe_get( $field['choices'], $value, $value );
if ( $field['return_format'] === 'label' ) {
$value = $label;
} elseif ( $field['return_format'] === 'array' ) {
$value = array(
'value' => $value,
'label' => $label,
);
}
return $value;
}