acf_field_flexible_content::load_value()publicACF 3.6

This filter is applied to the $value after it is loaded from the db

@type filter

{} Это метод класса: acf_field_flexible_content{}

Хуков нет.

Возвращает

$value.

Использование

$acf_field_flexible_content = new acf_field_flexible_content();
$acf_field_flexible_content->load_value( $value, $post_id, $field );
$value (обязательный)
-
$post_id (обязательный)
-
$field (обязательный)
-

Список изменений

С версии 3.6 Введена.

Код acf_field_flexible_content::load_value() ACF 5.10.2

function load_value( $value, $post_id, $field ) {

	// bail early if no value
	if ( empty( $value ) || empty( $field['layouts'] ) ) {

		return $value;

	}

	// value must be an array
	$value = acf_get_array( $value );

	// vars
	$rows = array();

	// sort layouts into names
	$layouts = array();
	foreach ( $field['layouts'] as $k => $layout ) {

		$layouts[ $layout['name'] ] = $layout['sub_fields'];

	}

	// loop through rows
	foreach ( $value as $i => $l ) {

		// append to $values
		$rows[ $i ]                  = array();
		$rows[ $i ]['acf_fc_layout'] = $l;

		// bail early if layout deosnt contain sub fields
		if ( empty( $layouts[ $l ] ) ) {

			continue;

		}

		// get layout
		$layout = $layouts[ $l ];

		// loop through sub fields
		foreach ( array_keys( $layout ) as $j ) {

			// get sub field
			$sub_field = $layout[ $j ];

			// bail ealry if no name (tab)
			if ( acf_is_empty( $sub_field['name'] ) ) {
				continue;
			}

			// update full name
			$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";

			// get value
			$sub_value = acf_get_value( $post_id, $sub_field );

			// add value
			$rows[ $i ][ $sub_field['key'] ] = $sub_value;

		}
		// foreach

	}
	// foreach

	// return
	return $rows;

}