class emailer {
static function notifyHeart($post_ID) {
$interests = get_user_meta(get_current_user_id(), 'interests');
$to = get_the_author_meta( 'user_email', get_current_user_id() );
$post = get_post($post_ID);
foreach($interests as $interest) {
if(has_tag($interest, $post)) {
$email = $to;
mail($email, "An article about Heart", 'A new post has been published about heart.');
break;
}
}
}
}
add_action('publish_post', array('emailer', 'notifyHeart'));
Here’s a reworked example. It retrieves all the tags you have in database as meta, checks each of them & if it matches the one in that post’s id, it will send the mail & break out of the loop.