Support

Account

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 🙂