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.

  • single.php is extremely broad template, something more specific might be in order. What progress have you made so far on code?
    – Rarst
    Commented Jun 11, 2014 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
    Commented Jun 11, 2014 at 19:18

1 Answer 1


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';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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