Support

Account

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

  • Hi John
    Thank you for helping me out.

    To make it more precise:

    I have a frontend form where anyone can add a post to a cpt.
    This post is saved as draft until the site-owner is publishing the post.

    After filling the form on frontend, a mail should go to the client with a thank you message that his post will be published if everyting is ok.

    Thats where I have used acf/save_post.

    This is my Code

    
    add_action('acf/save_post' , 'my_save_post', 20);
    function my_save_post($post_id) {
    
    	 // If not CPT, exit
        if( get_post_type($post_id) !== 'inserate' ) {
            return;
        }
    
        add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
        
    
    	// get custom fields (field group exists for content_form)
    	$name = get_field('name', $post_id);
        $email = get_field('email', $post_id); 
    
        $to = $email;
    	$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
        $subject = 'Thank you';
        $message = 'Thank you for submitting a post';
    
        wp_mail($to, $subject, $message, $headers );
    
        remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
    }
    
    

    Now my question is, to just send this mail after submitting the form, but not after publishing. At the moment the action is fired multiple times and I need a check for the post status or something else.

    Roman