ElaineMarley86
Member
Posted 8 months ago #
I'd like to have on my blog a page which shows to the logged in user only the posts of the logged in user.
Explanation: I'm user Charlie Brown, I log in, I want to see only postst of the author Charlie Brown (i.e. myself) inside this page.
How can I write this loop?
Thanks everyone!
Get the current user id (zero if not logged in) and add the 'author' argument to the query.
If you want to keep all previous arguments, use this:
$id = get_current_user_id();
if ($id) {
global $wp_query;
query_posts(
array_merge(
$wp_query->query,
array('author' => $id)
)
);
}
Otherwise, just create your own argument array for the query.
ElaineMarley86
Member
Posted 7 months ago #
Thanks, it works perfectly!