我有两种帖子类型,分别是“第一类帖子”和“第二类帖子”两种帖子类型都有完全相似的a类、b类、c类、d类,当“帖子类型一”中“a”类下的帖子发布时,会向“帖子类型二”中“a”类下的作者发送电子邮件通知。有人能给我推荐一个插件(免费或高级)来做到这一点吗?或者你知道怎么做吗?提前感谢:)
满足条件时发送电子邮件通知
1 个回复
SO网友:Johansson
您可以使用此代码在收到以下类型的邮件时自动发送电子邮件one
已发布。这是你的主题functions.php
:
<?php
function post_published_notification( $ID, $post ) {
$type = get_post_type($ID);
if ($type == \'post-type-one\'){
$author = $post->post_author; /* Post author ID. */
$name = get_the_author_meta( \'display_name\', $author );
$email = get_the_author_meta( \'user_email\', $author );
$title = $post->post_title;
$permalink = get_permalink( $ID );
$edit = get_edit_post_link( $ID, \'\' );
$to[] = sprintf( \'%s <%s>\', $name, $email );
$subject = sprintf( \'Published: %s\', $title );
$message = sprintf (\'%s, Your article “%s” has been published.\' . "\\n\\n", $name, $title );
$message .= sprintf( \'View: %s\', $permalink );
$headers[] = \'\';
wp_mail( $to, $subject, $message, $headers );
}
}
add_action( \'publish_post\', \'post_published_notification\', 10, 2 );
?>
您可以阅读和代码,并根据需要修改所需的部件。如果你的问题清楚的话,我可以发布一个更准确的答案。然而,函数本身很有解释性。