wp_mail send email twice inside function updated_postmeta

by Muhammad Ibrahim   Last Updated April 16, 2018 07:08 AM

I make a custom function so when postmeta updated to specific value i send custom email use wp_mail. email successfully send but it create twice at same time.

here my code

function email_notification_by_status()
{

// Global Variable

$post_id = get_The_ID();
$user = wp_get_current_user();
$user_id = get_current_user_id();
$blog_id = get_current_blog_id();
$dd_status = get_post_meta($post_id, 'screening_status', true);
$dd_analyst = get_post_meta($post_id, 'select_analyst', true);

//Completed

if ('Completed' == $dd_status)
    {

    $args = array(
        'role' => 'client',
        'blog_id' => $blog_id
    );
    $client_infos = get_users($args);
    foreach($client_infos as $client_info)
        {
        $client_email = $client_info->user_email;
        $to = $client_email;
        $subject = 'Due diligence is Complete';
        $body = 'Lorem ipsum';
        wp_mail($to, $subject, $body);
        }
    }
}

add_filter('updated_postmeta', 'email_notification_by_status');

could please tell me what's wrong with my code. thanks



Related Questions


Frontend form with multiple posts

Updated July 02, 2018 14:08 PM

How trigger to save post when updating post meta

Updated October 14, 2017 08:08 AM



Save metabox with multiple checkbox array

Updated September 24, 2016 09:03 AM