acf_field_repeater::format_value
This filter is appied to the $value after it is loaded from the db and before it is returned to the template
Метод класса: acf_field_repeater{}
Хуков нет.
Возвращает
Массив. $value The modified value.
Использование
$acf_field_repeater = new acf_field_repeater(); $acf_field_repeater->format_value( $value, $post_id, $field, $escape_html );
- $value(разное) (обязательный)
- The value which was loaded from the database.
- $post_id(разное) (обязательный)
- The
$post_idfrom which the value was loaded. - $field(массив) (обязательный)
- The field array holding all the field options.
- $escape_html(true|false)
- Should the field return a HTML safe formatted value.
По умолчанию:false
Список изменений
| С версии 3.6 | Введена. |
Код acf_field_repeater::format_value() acf field repeater::format value ACF 6.4.2
public function format_value( $value, $post_id, $field, $escape_html = false ) {
// bail early if no value
if ( empty( $value ) ) {
return false;
}
// bail early if not array
if ( ! is_array( $value ) ) {
return false;
}
// bail early if no sub fields
if ( empty( $field['sub_fields'] ) ) {
return false;
}
// loop over rows
foreach ( array_keys( $value ) as $i ) {
// loop through sub fields
foreach ( array_keys( $field['sub_fields'] ) as $j ) {
// get sub field
$sub_field = $field['sub_fields'][ $j ];
// bail early if no name (tab)
if ( acf_is_empty( $sub_field['name'] ) ) {
continue;
}
// extract value
$sub_value = acf_extract_var( $value[ $i ], $sub_field['key'] );
// update $sub_field name
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// format value
$sub_value = acf_format_value( $sub_value, $post_id, $sub_field, $escape_html );
// append to $row
$value[ $i ][ $sub_field['_name'] ] = $sub_value;
}
}
return $value;
}