WordPress- Only show posts of users that are logged in

76 views
asked Nov 11, 2012 in Website Builder by SunFun (3,000 points)
Hi there
I want to add a page on my site that shows only posts of the logged in user. So that if a user wants to display only his posts he/she will be able to do so.
Can anyone please help me do this?
Thanks

1 Answer

0 like 0 dislike
answered Nov 11, 2012 by expert (14,380 points)
First get the current user id  and then add the 'author' argument to your query.
To keep all the previous arguments, do this:
$id = get_current_user_id();
if ($id) {
   global $wp_query;
   query_posts(
      array_merge(
         $wp_query->query,
         array('author' => $id)
      ) );}
...