我創建一個函數,當我的WordPress博客上發佈帖子時,發送電子郵件到郵件列表。WordPress的:不要設法從php函數檢索作者的名字
function announce_post($post_id){
$email_address = '[email protected]';
$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\" <[email protected]>")) { }
}
add_action('publish_post','announce_post');
,因爲它是功能效果很好,但我當然會與實際職位的作者姓名替換SOMEONE
。我無法找回那個。
get_the_author($post_id)
,get_post_meta($post_id, 'author_name', true)
也沒有其他的我試過,不記得工作。一切都剛剛返回""
。
那麼,在給定帖子ID的情況下,檢索帖子作者姓名的正確方法是什麼?
檢查語法高亮,看到了嗎?這是你的代碼中的一個問題,你會得到語法錯誤嗎? – elclanrs
不,它發生在用假人替換博客標題時。 –
該功能在服務器上工作,現在看起來也不錯... –