Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created June 4, 2019 07:26
Show Gist options
  • Save yanknudtskov/cfa35d90ebab48f98db67815c662a8e4 to your computer and use it in GitHub Desktop.
Save yanknudtskov/cfa35d90ebab48f98db67815c662a8e4 to your computer and use it in GitHub Desktop.
Check if an Advanced Custom Field (ACF field) value changed.
<?php
// Remember to insert the {$field_name}
add_filter('acf/update_value/name={$field_name}', 'yanco_check_change_of_field_value', 10, 3);
function yanco_check_change_of_field_value( $value, $post_id, $field) {
$old_value = get_post_meta($post_id, $field['name'], true);
if ($old_value != $value) {
// it changed
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment