acf/update_value

Overview

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

Requirements

  • ACF version 4.0.0 or above

Parameters

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

Usage

There are 4 ways to hook into acf_update_value.

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

functions.php

<?php

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

    // do something else to the $post object via the $post_id
	
	// return
    return $value;
    
}

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

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

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

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

?>

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.