Home Forums ACF PRO Send email when status turns from draft to published


Send email when status turns from draft to published

  • Hi there!

    I have a front end form that creates a custom post type with a draft status that we then moderate and publish. I was wondering if it was possible to send the visitor an email once their post was published. I found the code below on the WordPress forums, but I’m not sure how to get it to send the email to an address from a ACF field. Any ideas?


    add_action( 'save_post', 'send_email' );
    function send_email( $post_id ) {
    // lets check if post is not revision
    	if ( !wp_is_post_revision( $post_id ) ) {
    		$post_url = get_permalink( $post_id );
    		$subject = 'Image is approved';
    		$message = "Your image is approved:\n\n";
    		$message .= "<a href='". $post_url. "'>Click here to view</a>\n\n";
    		$email = get_post_meta($post_id, 'email')
    		//sends email
    		wp_mail($email, $subject, $message );
  • is the name of the field email

    change this line to:

    $email = get_post_meta($post_id, 'email', true)

    and change the email to the name of the ACF field if it’s different.

  • Just the ticket, thanks!

  • hey Leanda,
    I have tried your code. the get_post_meta() function don’t return anything,
    could you please help me to solve this problem.

  • get_post_meta() will not work in this case for a new post. Using the above code the hook ‘save_post’ is probably happening before ACF fields are updated.

    Try acf/save+post.

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

The topic ‘Send email when status turns from draft to published’ is closed to new replies.