acf_search_fields()ACF 5.7.11

acf_search_fields

Searches an array of fields for one that matches the given identifier.

Хуков нет.

Возвращает

(int|false).

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

acf_search_fields( $id, $fields );
$id((int|string)) (обязательный)
The field ID, key or name.
$fields (обязательный)
-

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

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

Код acf_search_fields() ACF 5.10.2

function acf_search_fields( $id, $fields ) {

	// Loop over searchable keys in order of priority.
	// Important to search "name" on all fields before "_name" backup.
	foreach ( array( 'key', 'name', '_name', '__name' ) as $key ) {

		// Loop over fields and compare.
		foreach ( $fields as $field ) {
			if ( isset( $field[ $key ] ) && $field[ $key ] === $id ) {
				return $field;
			}
		}
	}

	// Return not found.
	return false;
}