WordPress post update AFTER ACF field updates

前端 未结 2 1230
天涯浪人
天涯浪人 2021-01-26 12:04

The code below sends out an email every time I (change the STATUS field and then) safe/update the post. But it\'s not working the way I want and I know whats\'s wrong:

T

2条回答
  •  遥遥无期
    2021-01-26 12:36

    UPDATE 2 Got it working. Code below:

    add_action('acf/save_post', 'yl_send_booking_email_after_status_update', 5);
    function yl_send_booking_email_after_status_update( $post_id ) {
    
        // Get submitted values.
        $values = $_POST['acf'];
    
        // Check if a specific value was updated.
        if( isset($_POST['acf']['field_5ed8117407663']) ) {
    
            $to         = $_POST['acf']['field_5ed41758ed4b5'];
            $subject    = $_POST['acf']['field_5ed81174076f2'];
            $message    = $_POST['acf']['field_5ed8117407741'];
    
            $headers = array
                (
                'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>',
                'Bcc: ' . get_bloginfo('admin_email'),
                'X-Mailer: PHP/' . phpversion(),
                'MIME-Version: 1.0',
                'Content-type: text/html; charset=iso-8859-1'
            );
            $headers = implode( "\r\n" , $headers );
    
            wp_mail( $to, $subject, $message, $headers );
    
        }
    }
    

提交回复
热议问题