Skip to content

Instantly share code, notes, and snippets.

@dankoch-cz
Last active June 19, 2022 14:43
Show Gist options
  • Select an option

  • Save dankoch-cz/eaf05025e10893b3e97c5cefa7bc9fa4 to your computer and use it in GitHub Desktop.

Select an option

Save dankoch-cz/eaf05025e10893b3e97c5cefa7bc9fa4 to your computer and use it in GitHub Desktop.
ACF check old custom field value and compare to new value
<?php
//Documentation: https://www.advancedcustomfields.com/resources/acf-save_post/
add_action('acf/save_post', 'vk_acf_save_post', 5);
function vk_acf_save_post( $post_id ) {
//Bail if post type is not equal "tickets"
if ( get_post_type( $post_id ) != 'tickets' ) {
return;
}
// Get previous values.
$old_state = get_post_meta($post_id, 'cf_name', true);
// Get submitted values.
$new_state = '';
if(isset($_POST['acf']['field_62a4a40d34d6b'])) {
$new_state = $_POST['acf']['field_62a4a40d34d6b'];
}
// Check if a specific value was updated.
if($old_state != $new_state) {
//Do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment