Send specific users an email when posts are published

Do you know if your wp_mail() function is working at all?
Do you know whether or not your function isn’t failing higher in the chain?

I’d re-write the function like this, which makes it a little easier to read and also slightly more efficient as we are only running functions that we absolutely need to given a certain condition being met.

Also, I’ve removed the get_field() function call which is just a wrapper for get_post_meta().

Storing $post_id = $post->ID has also been removed because at this stage there is no need to manipulate or cache the ID for any particular reason, so it just cleans things up a little.

If you know that your call to the specific_users custom field returns a serialized array then you can add the true parameter after the meta_key to receive back an unserialized array, otherwise omit the true value.

isset will return true even if the array is empty and IF there are no results in the array WordPress will in fact return an empty array, unless the true parameter is set in which case it will return an empty string, so a call the call to isset has been removed and replaced with !empty($array).

From this point you can debug the function somewhat easier…

function notify_growers($post) {
    //if NOT post type 'grower_posts' then exit;
    if ( $post->post_type != 'grower_posts' ) 
         return;

    //if email already sent then exit.
    if ( get_post_meta( $post->ID, 'emailsent', true ) )
         return;

    //if email not sent then get an array of users to email
    $specific_users = get_post_meta($post->ID, 'specific_users');

    //if $specific_users is an array and is not empty then send email. 
    if(is_array($specific_users) && !empty($specific_users)) { 
        foreach($specific_users as $specific_user) {
            //add mail logic here, $to, $subject, $message
            wp_mail($to, $subject, $message );
        }
        unset($specific_user);

        //prevent emails from being sent by updating post meta field
        update_post_meta( $post->ID, 'emailsent', true );
    }   

}

add_action( 'draft_to_publish', 'notify_growers' );
add_action( 'new_to_publish', 'notify_growers' );