acf/load_field
Allows you to change the settings array of any field after it is loaded.
A field is loaded whenever it is displayed or its value is requested. This filter applies both to fields saved in the database and to fields registered locally through PHP or JSON.
This filter provides modifiers for specific fields. The following filter names are available:
acf/load_field- Applies to all fields.acf/load_field/type={$type}- Applies to all fields of a specific type, such as select.acf/load_field/name={$name}- Applies to all fields with a specific name, such asproduct_photo.acf/load_field/key={$key}- Applies to all fields with a specific key, such asfield_123abcf.
Usage
add_filter( 'acf/load_field', 'wp_kama_acf_load_field_filter' );
/**
* Function for `acf/load_field` filter-hook.
*
* @param array $field The field array.
*
* @return array
*/
function wp_kama_acf_load_field_filter( $field ){
// filter...
return $field;
}
- $field(array)
- An array of all field settings.
Examples
#1 Make a field required
function my_acf_load_field( $field ) {
$field['required'] = true;
return $field;
}
// Make all fields required
// add_filter('acf/load_field', 'my_acf_load_field');
// Make only all select fields required
// add_filter('acf/load_field/type=select', 'my_acf_load_field');
// Make only the field named 'custom_select' required
add_filter('acf/load_field/name=custom_select', 'my_acf_load_field');
// Make only the field with the key "field_123abcf" required.
// add_filter('acf/load_field/key=field_123abcf', 'my_acf_load_field');
#2 Process shortcodes in fields in the admin area
The example is available in a separate note.
Changelog
| Since 5.0.0 | Introduced. |
Where the hook is called
acf/load_field
acf/includes/acf-field-functions.php 70
$field = apply_filters( 'acf/load_field', $field );