Support

Account

Home Forums General Issues Have a CPT Form Send an Email

Solved

Have a CPT Form Send an Email

  • Hello,

    I have a ACF form which, when submitted, creates a new post under a custom type type. My question is, can this form also send an email to someone to notify them that a new post has been created?

    Here is my code:

    //Add ACF Front End Content Submission Form
    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
      
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => $_POST["fields"]['field_52b2ffdfdcad1'] ,
            'post_type'  => 'links' ,        
        ); 
      
        // insert the post
        $post_id = wp_insert_post( $post );
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
      
        // return the new ID
        return $post_id;
    }
      
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
  • You should be able to throw this in before the return, building the variables first.
    <?php wp_mail( $to, $subject, $message, $headers, $attachments ); ?>

    http://codex.wordpress.org/Function_Reference/wp_mail has the details.

  • How would this be achieved in ACF 5?

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

The topic ‘Have a CPT Form Send an Email’ is closed to new replies.