I ran a test and the following works:
global $testMe;
$testMe = 0;
function my_acf_update_value( $value, $post_id, $field ) {
global $testMe;
$testMe = $value;
return $value;
}
add_filter('acf/update_value/key=field_5308e5e79784b', 'my_acf_update_value', 10, 3);
// Test: Apply the filter
apply_filters('acf/update_value/key=field_5308e5e79784b','a','b','c');
// end Test
echo $testMe; // prints 'a'
So, in principle, your code is functional. There are a couple of things that I can think that may be going wrong.
- You are adding the filter after the hook has ran. Place that test
apply_filters
before the rest of the code and it won’t work. - You have the hook name wrong.
Other than that, it should work. However, this global
variable technique is a bit messy. Might I suggest something like this:
function my_acf_grab_value($value,$echo = false) {
static $var = 0;
if (false === $echo) {
$var = $value;
} else {
return $var;
}
}
function my_acf_update_value( $value, $post_id, $field ) {
my_acf_grab_value($value);
return $value;
}
add_filter('acf/update_value/key=field_5308e5e79784b', 'my_acf_update_value', 10, 3);
// Test: Apply the filter
apply_filters('acf/update_value/key=field_5308e5e79784b','Yay','b','c');
// end test
echo my_acf_grab_value('',true);
Or this:
function my_acf_update_value( $value="", $post_id = 0, $field = '' ) {
static $var = 0;
if (!empty($value)) {
$var = $value;
} else {
return $var;
}
return $value;
}
add_filter('acf/update_value/key=field_5308e5e79784b', 'my_acf_update_value', 10, 3);
// Test: Apply the filter
apply_filters('acf/update_value/key=field_5308e5e79784b','Yay','b','c');
// end test
echo my_acf_update_value();