acf_search_fields()
acf_search_fields
Searches an array of fields for one that matches the given identifier.
No Hooks.
Returns
(Int|false).
Usage
acf_search_fields( $id, $fields );
- $id((int|string)) (required)
- The field ID, key or name.
- $fields(required)
- .
Changelog
| Since 5.7.11 | Introduced. |
acf_search_fields() acf search fields code ACF 6.0.4
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;
}