acf/load_field

Overview

This filter allows you to modify a field after it is loaded from the database and before its 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 its type
  3. acf/load_field/name={$field_name} – filter for a specific field based on its name
  4. acf/load_field/key={$field_key} – filter for a specific field based on its key

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');

?>

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.