acf/load_field

Last updated Feb 17, 2022

Description

Filters the $field settings array after being loaded.

A field is loaded anytime it is displayed, or its value is loaded. This filter applies to both fields saved in the database and also those registered locally via PHP or JSON.

Changelog

  • Added in version 4.0.0

Parameters

apply_filters( 'acf/load_field', $field );
  • $field (array) The field array containing all settings.

Modifers

This filter provides modifiers to target 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.
  • acf/load_field/name={$name} Applies to all fields of a specific name.
  • acf/load_field/key={$key} Applies to all fields of a specific key.

Example

This example demonstrates how to modify a specific field’s settings.

functions.php

<?php
function my_acf_load_field( $field ) {
    $field['required'] = true;
    $field['choices'] = array(
        'custom'    => 'My Custom Choice',
        'custom_2'  => 'My Custom Choice 2'
    );
    return $field;
}

// Apply to all fields.
// add_filter('acf/load_field', 'my_acf_load_field');

// Apply to select fields.
// add_filter('acf/load_field/type=select', 'my_acf_load_field');

// Apply to fields named "custom_select".
add_filter('acf/load_field/name=custom_select', 'my_acf_load_field');

// Apply to field with key "field_123abcf".
// add_filter('acf/load_field/key=field_123abcf', 'my_acf_load_field');
Supercharge Your Website With Premium Features Using ACF PRO

Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.

Explore Features View Pricing

PRO Features
ACF Blocks
Options Pages
PRO Fields
Repeater
Flexible Content
Gallery
Clone