WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having trouble finding a solution or the correct tutorial on how to get this done, I have been looking for weeks and still no outcome. What I am trying to accomplish is display all post on the front end (single.php) of an author (Author A) who is logged on. When Author A logs off all the posts on single.php will be removed leaving a message (you must be logged in to view this page). Then when Author B logs on all of Authors B post will be displayed on single.php. Each post is being generate by a custom post type called projects, which have the ability to assign an author. I am trying to accomplish this without a plugin.

Any help would be appreciated.

share|improve this question
single.php is extremely broad template, something more specific might be in order. What progress have you made so far on code? – Rarst Jun 11 '14 at 19:09
Not too much as in what I am trying to accomplish. @Rarst. What I am doing is creating a client portal where a client can view their project progress. When a client logs in they will be redirected to a custom page called dashboard. Once you are on the dashboard pages it will pull information from my custom post type called projects. Each projects will have an assign author (client). When client A logs in I want to display only the post that are assigned to that client. I am able to display all post on the projects page, I just can not display them based on the user who is logged in. – bigant841 Jun 11 '14 at 19:18
up vote 2 down vote accepted

Check if a user is logged in using is_logged_in. If a user is logged in modify the query using pre_get_posts filtering posts by the current author ID.

if ( is_user_logged_in() ) :
  function filter_posts_by_author( $query ) {
    global $current_user;
    $query->set( 'author', $current_user->ID );
  add_action( 'pre_get_posts', 'filter_posts_by_author' );
  // ... loop
else : 
  echo 'you must be logged in to view this page';
share|improve this answer
That is perfect. Thank you so much @Joey Yax – bigant841 Jun 11 '14 at 19:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.