我正在尝试在创建新帖子后发送电子邮件。它需要在创建帖子后发送,因为我想在电子邮件中包含帖子类别。wp_after_insert_post
似乎不起作用,因为没有发送电子邮件。我尝试使用与publish_post
钩子相同的代码,它确实可以正确发送电子邮件,但我无法在电子邮件中使用类别名称。
function new_post_email( $post_id ) {
$categories = get_the_category( $post_id );
$subject = $categories[0]->name;
$sent = wp_mail($to = 'my@email.com', $subject, $message = 'Test message');
};
add_action( ' wp_after_insert_post', 'new_post_email');
有什么解决办法吗?提前致谢