Home › Forums › ACF PRO › Action hook when specific field changes › Reply To: Action hook when specific field changes
Hi @giu-tae-kim
I think you can use the acf/update_value filter or the acf/save_post action hooks to do it. Here’s the example how to do it with acf/update_value
:
function my_acf_update_value( $value, $post_id, $field ) {
// only do it to certain custom fields
if( $field['name'] == 'custom_field_name' ) {
// get the old (saved) value
$old_value = get_field('custom_field_name', $post_id);
// get the new (posted) value
$new_value = $_POST['acf']['field_1234567890abc'];
// check if the old value is the same as the new value
if( $old_value != $new_value ) {
// Do something if they are different
} else {
// Do something if they are the same
}
}
// don't forget to return to be saved in the database
return $value;
}
// acf/update_value - filter for every field
add_filter('acf/update_value', 'my_acf_update_value', 10, 3);
Where ‘field_1234567890abc’ is the field key of your custom field(‘custom_field_name’ in this case).
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.