Support

Account

Home Forums General Issues Email User within a user field Reply To: Email User within a user field

  • I had gone in a different way but I am back to this, I know it’s been awhile. Here is what I have come up with, but it isn’t working, any ideas?

    add_action( 'acf/save_post', 'my_acf_save_hook_email', 5); function my_acf_save_hook_email( $post_id ) { 
    
    // bail early if no pds_project_manager if( empty($_POST['pds_project_manager']) ) { 
    return; }
    
    // Get the value of the ACF field $project_managers = get_field('pds_project_manager', ''); 
    // Create an empty array to store the emails $emails_to_send = array(); 
    
    // Loop through the project managers 
    foreach ($project_managers as $project_manager) { 
    // Get the user data 
    $user_data = get_userdata($project_manager); 
    
    // Check if the user already exists in the array 
    if (!in_array($user_data->ID, $emails_to_send)) { 
    // Add the user to the emails to send 
    $emails_to_send[] = $user_data->user_email; } } 
    // Send emails to the users 
    foreach ($emails_to_send as $email_to_send) { 
    // Send the email 
    wp_mail($email_to_send, 'You Have Been Added To A Project', 'You have been added to a project. Please check the project page for more information.'); } }