acf/load_field

Overview

This filter allows you to modify a field after it is loaded from the database and before it’s value has been loaded.

Changelog

Parameters

  • $field – the field settings array. This can be modified and then returned

Usage

There are 4 ways to hook into acf_load_field.

  1. acf/load_field – filter for every field
  2. acf/load_field/type={$field_type} – filter for a specific field based on it’s type
  3. acf/load_field/name={$field_name} – filter for a specific field based on it’s name
  4. acf/load_field/key={$field_key} – filter for a specific field based on it’s name

This code is used in the functions.php file

functions.php

<?php

function my_acf_load_field( $field ) {
	
    $field['choices'] = array(
        'custom' => 'My Custom Choice'
    );

    return $field;
    
}


// all
// add_filter('acf/load_field', 'my_acf_load_field');

// type
add_filter('acf/load_field/type=select', 'my_acf_load_field');

// name
// add_filter('acf/load_field/name=my_select', 'my_acf_load_field');

// key
// add_filter('acf/load_field/key=field_508a263b40457', 'my_acf_load_field');

?>

Hi all. Server maintenance scheduled this Sunday 28th May. Learn more