I am currently using Advanced Custom Fields in my WordPress project, and I need a function to trigger when the custom fields for a post update. I have thus implemented a hook on ‘acf/save_post’ but it is not triggering. I have inserted the code below into the functions.php file, but to no avail.
The function itself works fine and triggers if I change the hook to ‘save_post’. However, ‘save_post’ does not contain the updated ACF fields I will eventually need.
I AM updating ACF fields, so I believe it should trigger. Any help with this would be greatly appreciated!
My hook:
add_action('acf/save_post', 'my_acf_save_post');
function my_acf_save_post($post_id)
{
$existing_data = file_get_contents('rest-data-cache.json');
$decoded_file = json_decode($existing_data);
$decoded_file->output = 'this worked';
$responseData = json_encode($decoded_file);
file_put_contents('rest-data-cache.json', $responseData);
}
the acf/save_post hook only happens when a post or something else is submitted that has ACF fields and some value in those fields has been changed.