我正在创建一个功能,当帖子发布在我的 WordPress 博客上时,它会向邮件列表发送电子邮件。
function announce_post($post_id){
$email_address = 'address.of@the-mailing.list';
$subject = "New Post: " . get_the_title($post_id);
$body = "Hi,\r\n\r\n" .
"SOMEONE has just published the article \"" .
get_the_title($post_id) . "\" on \"BLOG TITLE\".\r\n\r\n" .
"You can read it at " . get_permalink($post_id) . "\r\n" .
"or visit BLOG_ADDRESS.\r\n\r\n" .
"Best wishes\r\n" .
"The Publisher";
if (wp_mail($email_address, $subject, $body, "From: \"BLOG TITLE\" <address.of@the-blog>")) { }
}
add_action('publish_post','announce_post');
因为它的功能运作良好,但当然我会用SOMEONE
实际帖子的作者姓名替换。而且我无法找回它。
既没有get_the_author($post_id)
,get_post_meta($post_id, 'author_name', true)
也没有其他我尝试过但不记得的方法。一切刚刚回来""
。
那么在给定帖子ID的情况下,检索帖子作者姓名的正确方法是什么?