_acf_field_has_relational_fields() │ ACF 6.8.11

The internal ACF function to return whether a field is, or contains, a Relationship, Post Object or Page Link field, at any depth inside Repeater, Group, Clone and Flexible Content fields.

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

boolean.

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

_acf_field_has_relational_fields( $field );
$field(массив) (обязательный)
The field array.

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

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

Код _acf_field_has_relational_fields() ACF 6.8.11

function _acf_field_has_relational_fields( $field ) {
	static $cache = array();

	$key = isset( $field['key'] ) ? (string) $field['key'] : '';

	if ( '' !== $key && isset( $cache[ $key ] ) ) {
		return $cache[ $key ];
	}

	$has_relational = in_array( $field['type'] ?? '', array( 'relationship', 'post_object', 'page_link' ), true );
	$children       = acf_get_array( $field['sub_fields'] ?? array() );

	foreach ( acf_get_array( $field['layouts'] ?? array() ) as $layout ) {
		$children = array_merge( $children, acf_get_array( $layout['sub_fields'] ?? array() ) );
	}

	foreach ( $children as $child ) {
		if ( $has_relational ) {
			break;
		}

		$has_relational = is_array( $child ) && _acf_field_has_relational_fields( $child );
	}

	if ( '' !== $key ) {
		$cache[ $key ] = $has_relational;
	}

	return $has_relational;
}