WordPress- Only show posts of users that are logged in

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?

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;
         array('author' => $id)
      ) );}