Home Forums Backend Issues (wp-admin) Sending mail containing ACF fields upon post creation


Sending mail containing ACF fields upon post creation

  • I wrote a function that hooks in to the ‘save_post’ action. This function sends an email containing some ACF fields of the post that triggers the function. Here is the code (without the sensitive data, obviously):

    add_action('save_post_configuration', __NAMESPACE__ . '\\new_order_mail', 10, 3);
    function new_order_mail( $post_id, $post, $update ){
        if( !$update ) {
          //mail customer
          $headers[]  = 'From: Someone <[email protected]>';
          $headers[]  = 'Content-Type: text/html; charset=UTF-8';
          $to = get_field('email', $post_id);
          $subject = 'Subject';
          $message = get_field('name', $post_id) . ' ' . get_field('email', $post_id);
          wp_mail($to, $subject, $message, $headers);

    This works without the custom fields, and when if( !$update ) is changed to if( $update ) it shows the custom fields when a post is updated. It really only doesn’t display the values when the post has just been created. Tried using the field keys too, but no luck.

    Any idea what could cause this?

  • Are you adding the post on the front end of in the admin?

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

You must be logged in to reply to this topic.