非常感谢你,弗雷兹!这对我帮助很大:)
我从高级自定义字段中找到了另一个钩子(acf/save_posts), 现在有一个可行的(我认为)解决方案!
参考号:https://www.advancedcustomfields.com/resources/acf-save_post/
我刚刚通过检查其中一个自定义字段的新旧值进行了测试,该函数似乎起到了作用。下一个问题;如何才能做到更干净?我有8个自定义字段,用我在下面代码中所做的方式检查它们似乎非常业余。是否有更好的方法为所有8个字段设置“检查旧值与新值”?
add_action(\'acf/save_post\', \'teams_update_notification\', 5);
function teams_update_notification( $post_ID ) {
// Check that it is the correct post type
if(get_post_type($post_ID) == \'teams\') {
// Get post name
$post_title = get_the_title( $post_id );
// New and old field value
$team_name = get_field(\'team_name\', $post->ID);
$team_name_new = \'\';
if (isset($_POST[\'acf\'][\'field_12345\'])) {
$team_name_new = $_POST[\'acf\'][\'field_12345\'];
}
if ($team_name_new != $team_name) {
$team_name_updated = $_POST[\'acf\'][\'field_12345\'];
}
// SET UP MAIL
$subject = $post_title . \' has been updated\';
$headers = array(\'Content-Type: text/html; charset=UTF-8\');
$message .= $post_title . \'has been updated\' . "\\r\\n";
$message .= $team_name_updated;
// Send email to admin.
wp_mail( \'[email protected]\', $subject, $message, $headers );
}
}