最后,我检查并在每次保存时更新一个新的元值。
$screen = get_current_screen();
if ( $screen->base == \'post\' && $screen->post_type == \'sessions\') {
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE ) return;
if ( isset( $_POST[\'session_status_tax\'] ) ) {
$status = $_POST[\'session_status_tax\'];
} else {
$status = \'\';
}
$prev_term = get_post_meta( $post_id, \'prev_term\', \'true\' );
if ( $status === \'status-approved\' && $status !== $prev_term ) {
write_post_log($post_id, \'Approved\' );
send_email( $post_id, \'Approved\' );
}
update_post_meta( $post_id, \'prev_term\', $status );
}
}