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\'));
这是一个重新设计的示例。它检索数据库中作为meta的所有标记,并检查每个标记&;如果它与该帖子id中的匹配,它将发送邮件;打破循环。