在wordpress中,我們需要在分配給作者的作者的基礎上向正文添加一個「按」行。這需要在作者創建帖子時發生。我的代碼如下所示:在content_pre_save上添加作者
function append_author($content, $post_id) {
$author_id = get_post_field('post_author', $post_id);
$author_meta = get_user_meta($author_id);
$author = '<div class="block-author">By '.$author_meta[first_name][0]." ".$author_meta[last_name][0].'</div>';
return $author.$content;
}
add_filter('content_save_pre', 'append_author');
雖然這裏的問題是,當管理員創建一個作家後,只是分配通過筆者覆蓋下拉的作者,代碼將插入admin作爲作者。
我認爲這是因爲內容還沒有保存,系統默認情況下會將該文章的創建者指定爲作者?如果是這樣的話,有什麼辦法可以獲得content_author_override字段的值來讓作者分配並使用它插入'byline'?
我知道$content
是帖子的內容,但是author id的變量是什麼?
下面的答案對您有幫助嗎? – yivi