Home › Forums › Backend Issues (wp-admin) › acf/save_post – execute only when value of field has changed › Reply To: acf/save_post – execute only when value of field has changed
here the full code maybe better to see what i have in mind.
add_action('acf/save_post', 'save_customerdata', 5);
function save_customerdata( $post_id ) {
if( is_admin() ) {
return;
}
if ( $_POST['acf']['field_5fd213a8c6dfe'] != get_field('field_5fd213a8c6dfe') ) {
$plz = $_POST['acf']['field_5fd213a8c6dfe'];
}
if ( $_POST['acf']['field_5fd213f4c6e02'] != get_field('field_5fd213f4c6e02') ) {
$street = $_POST['acf']['field_5fd213f4c6e02'];
}
if ( $_POST['acf']['field_5fd21405c6e03'] != get_field('field_5fd21405c6e03') ) {
$ptel = $_POST['acf']['field_5fd21405c6e03'];
}
if ( $_POST['acf']['field_5fd21410c6e04'] != get_field('field_5fd21410c6e04') ) {
$pfax = $_POST['acf']['field_5fd21410c6e04'];
}
if ( !empty( $plz ) OR !empty( $street ) OR !empty( $ptel ) OR !empty( $pfax ) ) {
$post = get_post( $post_id );
$user_id = str_replace("user_", "", $post_id);
$user_info = get_userdata($user_id);
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
$user_email = $user_info->user_email;
$user_login = $user_info->user_login;
$to = '[email protected]';
$headers = array('From: ' . $user_info->first_name. ' '.$user_info->last_name . ' <'.$user_info->user_email.'>');
$subject = 'Profile Updated';
$body = $user_info->first_name. ' '.$user_info->last_name. ' hat das Profil aktualisiert' . "\r\n";
$body .= 'Benutzername: ' . $user_login . "\r\n";
if ( !empty( $plz ) ) {
$body .= 'PLZ / ORT wurde aktualisiert.' . "\r\n";
}
if ( !empty( $street ) ) {
$body .= 'Strasse / Hausnummer wurde aktualisiert.' . "\r\n";
}
if ( !empty( $ptel ) ) {
$body .= 'Telefonnummer wurde aktualisiert.' . "\r\n";
}
if ( !empty( $pfax ) ) {
$body .= 'Faxnummer wurde aktualisiert.' . "\r\n";
}
wp_mail($to, $subject, $body, $headers );
}
}
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.