Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14318 reviews 1707 hosting providers

Questions & Answers

WordPress- Only show posts of users that are logged in

Nov 11, 2012 by SunFun
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 votes
Nov 11, 2012 by expert
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)
      ) );}