我有以下功能,可以向custom post type 当这篇文章发表时,这很好,但我希望它不会在以后的任何编辑中给他们发电子邮件,以避免意外地给他们发送大量电子邮件。
这是我目前的职能:
//email authors
function authorNotification($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$message = "Hi ".$author->display_name.".
A document for you, ".$post->post_title." has just been published or edited and requires your attention.
You will be taken to the document after you log in from this link: ".get_permalink( $post_id ).".
";
wp_mail($author->user_email, "An online document has been made or edited for you.", $message);
}
add_action(\'publish_portaldocuments\', \'authorNotification\');
我想知道它是否和{$old\\u status}
to{$new\\u status}和{$new\\u status}{$post->post\\u type}挂钩有关,如本页所示:Post publish only hook?有人能帮忙吗,因为我不知道如何用自定义的帖子类型实现它。谢谢:-)
Update: 这对我很有用:
// SEND EMAIL TO AUTHOR OF A CUSTOM POST TYPE ONCE POST IS PUBLISHED
function authorNotification($post_id) {
if( ( $_POST[\'post_status\'] == \'publish\' ) && ( $_POST[\'original_post_status\'] != \'publish\' ) ) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$message = "Hi ".$author->display_name.".
A document for you, ".$post->post_title." has just been published or edited and requires your attention.
You will be taken to the document after you log in from this link: ".get_permalink( $post_id ).".
";
wp_mail($author->user_email, "An online document has been made or edited for you.", $message);
}
}
add_action( \'publish_portaldocuments\', \'authorNotification\' );
最合适的回答,由SO网友:s_ha_dum 整理而成
是的,听起来你确实想post transition hook, 可能draft_to_publish
根据法典中的以下内容:
function your_callback( $post ) {
// Code here
}
add_action( \'draft_to_publish\', \'your_callback\' );
使用
authorNotification
-- 函数名--而不是
your_callback
. 你的情况应该很简单。
然而,您的项目的确切细节尚不清楚。你可能需要更复杂的东西。我不知道。