acf/update_field

Last updated Feb 17, 2022

Description

Used to modify the $field settings array before being saved into the database.

This filter should not be confused with acf/update_value which is used similarly to modify field values.

Changelog

  • Added in version 5.0.0

Parameters

apply_filters( 'acf/update_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/update_field Applies to all fields.
  • acf/update_field/type={$type} Applies to all fields of a specific type.
  • acf/update_field/name={$name} Applies to all fields of a specific name.
  • acf/update_field/key={$key} Applies to all fields of a specific key.

Example

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

functions.php

<?php
function my_acf_update_field( $field ) {

    // Ensure all "company" fields are required.
    if( strpos($field['name'], 'company') !== false ) {
        $field['required'] = true;
    }
    return $field;
}

// Apply to all fields.
add_filter('acf/update_field', 'my_acf_update_field', 10, 1);

// Apply to textarea fields.
// add_filter('acf/update_field/type=textarea', 'my_acf_update_field', 10, 1);

// Apply to fields named "hero_text".
// add_filter('acf/update_field/name=hero_text', 'my_acf_update_field', 10, 1);

// Apply to field with key "field_123abcf".
// add_filter('acf/update_field/key=field_123abcf', 'my_acf_update_field', 10, 1);
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