Home Forums ACF PRO acf/save_post – send email only once the posttype is created


acf/save_post – send email only once the posttype is created

  • Hello,

    I am working with WordPress and ACF Pro Fields.
    I want to let users fill out some form, after submit, I want to receive an E-Mail with all the information the user put in AND a specific posttype should be created in the WordPress backend(draft) so I can review it and then publish ist.

    All this works perfectly fine!
    BUT when I updated the post, I receive a NEW E-Mail with the same information and the updated content, I don’t want that, how can I stop this?

    Here is my Code

    <?php acf_form(array(
                            'field_groups' => array('group_5fc8d223090ce'),
                            'form' => false,
                            'post_id' => 'new_post',
                            'new_post' => array(
                                'post_type' => 'my_posttype',
                                'post_status' => 'draft',
                                'post_content' => true,
                        )); ?>
                            <input type="submit" id="issubmitform" name="issubmitform"
                                   class="acf-button button button-primary button-large" value="Submit">

    My function:

    add_action('acf/save_post' , 'my_save_post');
    function my_save_post($post_id) {
    if( get_post_type($post_id) !== 'my_posttype' ) {
    add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
       $name = get_field('my_acf_field', $post_id);
        $to = '';
        $headers = "Content-Type: text/html;  charset=UTF-8";
        $subject = 'My Subject' . $name;
        $message = "This is the message"
        wp_mail($to, $subject, $message, $headers );
        remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
    function my_acf_save_post3($post_id) {
        if ($_POST['issubmitform'] === "Submit"){
            wp_redirect( ''  ); exit;
    add_action('acf/save_post', 'my_acf_save_post3', 20);

    I am sure I am just missing something, any help would be appreciated

  • I had the same “issue”.

    I created a work around with an extra ACF field which will be filled on the first time after saving. For sending the email i check if that field is filled. If its empty, its a new post otherwise its an updated post

    if(empty(field)) { send email + fill field }

  • check the post status and only send the email if it is draft.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.