最合适的回答,由SO网友:Frank P. Walentynowicz 整理而成
如果您想发送电子邮件on first publish and on updates, 您可以通过使用{status
}_{post type
} 行动挂钩。将下面的代码放入当前主题的函数中。php:
add_action( \'publish_task\', \'wpse_admin_email\', 10, 2 );
function wpse_admin_email( $post_id, $post ) {
// prepare and send email code goes here...
}
如果您想发送电子邮件
on first publish only, 使用以下代码:
add_action( \'transition_post_status\', \'wpse_admin_email_once\', 10, 3 );
function wpse_admin_email_once( $new, $old, $post ) {
if ( $post->post_type == \'task\' && $new == \'publish\' && $old == \'auto-draft\' ) {
// prepare and send email code goes here...
}
}