![](/img/trans.png)
[英]WordPress Get Current Logged-in users post or posts with edit link
[英]In each wordpress post, get the role of the current logged-in user
我有幾篇文章,一些是由具有作者角色的用戶編寫的,而另一些是由訂閱者角色用戶編寫的。 我想知道,如果您僅在他們自己的帖子顯示中登錄訂閱者用戶,在包含他們自己的帖子的 div 上,額外的 class,但如果您僅在該作者的帖子中啟動作者,它將顯示在包含所有自己的帖子的相同 div,顯示與訂閱用戶不同的 class
echo $post_content;
$user = new WP_User($post->author_id);
$user_roles = $user->roles[0];
echo '<div class="file-adjuntos '.$user_online_class.' '.$user_roles.'">';
echo $this->uploads->show_uploaded_files($post->id, $post->uploads);
echo '</div>';
這上面它的作用是顯示發布帖子的用戶的角色,對所有帖子,擁有而不是擁有當前用戶,而你想要的是角色只會在當前的 div 中顯示一個額外的 class用戶的帖子。 我希望你明白我在找什么。 非常感謝你的幫助。 此致。
您正在為每個帖子創建一個新用戶,但您不想這樣做。
用這個替換你的代碼: echo $post_content;
$user = get_current_user_id();
$author_id= $post->post_author;
$user_roles = "";
if($user == $author_id)
$user_roles = $user->roles;
echo '<div class="file-adjuntos '.$user_online_class.' '.$user_roles.'">';
echo $this->uploads->show_uploaded_files($post->id, $post->uploads);
echo '</div>';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.