1 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以將帖子 ID 與作者一起傳遞,例如WP_Query
$args = array('author' => $current_user->ID,
'p' => get_the_ID() );
$author_posts = new WP_Query( $args );
但是,這似乎您正在做不需要的額外工作 - 您已經(jīng)在帖子頁面上,因此已經(jīng)設(shè)置了循環(huán)以顯示帖子詳細(xì)信息。
我假設(shè)您要做的是檢查它是否是登錄用戶自己的帖子,并且僅在是時(shí)顯示它。在這種情況下,您需要做的就是:
$current_user = wp_get_current_user();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
/* the user is logged in and the current logged-in user is the post author */
/* Show the post here....*/
}
else{
/* Author is not the logged in user!
Do whatever you want in this case...*/
}
- 1 回答
- 0 關(guān)注
- 175 瀏覽
添加回答
舉報(bào)