acf_update_value

Overview

This action works on version 3.5.8.2 and below. If using version 4, please use acf/update_value

Description

This hook allows you to modify the value of a field before it is saved to the database.

Requirements

  • ACF version 3.5.1 or above

Parameters

  • $value – the value of the field as found in the $_POST object
  • $field – the field object (actually an array, not object)
  • $post_id – the post id to save against

Usage

There are 4 ways to hook into acf_update_value.

  1. acf_update_value – filter for every value update
  2. acf_update_value-{$field_type} – filter for a value update based on it’s field type (added in 3.5.3)
  3. acf_update_value-{$field_name} – filter for a specific value update based on it’s field name
  4. acf_update_value-{$field_key} – filter for a specific value update based on it’s field key

This code is used in the functions.php file

<?php

function my_acf_update_value( $value, $field, $post_id )
{
    $value = "Custom value";

    // do something else to the $post object via the $post_id

    return $value;
}

// acf_update_value - filter for every field
add_filter('acf_update_value', 'my_acf_update_value', 10, 3);

// acf_update_value-{$field_type} - filter for a field based on it's field type
add_filter('acf_update_value-select', 'my_acf_update_value', 10, 3);

// acf_update_value-{$field_name} - filter for a specific field based on it's name
add_filter('acf_update_value-my_select', 'my_acf_update_value', 10, 3);

// acf_update_value-{$field_key} - filter for a specific field based on it's key
add_filter('acf_update_value-field_508a263b40457', 'my_acf_update_value', 10, 3);

?>