Display content based on a users login

I was wondering if this is possible. I created a client portal where they can see all of their work that was assigned to them (this is all being displayed on the frontend). Once they login, they are then redirect to their page. I am using the code below to display the projects related to the current user

 <?php if ( is_user_logged_in() ) : function filter_posts_by_author( $query ) { 
        global $current_user; get_currentuserinfo();
        $query->set( 'author', $current_user->ID );
      }
        add_action( 'pre_get_posts', 'filter_posts_by_author' );?> 
 <h2>Post Goes here</h2>
 <?php else: wp_die('Sorry, you do not have access to this page. Please <a href="/#/">sign in</a> to view this page.');endif; ?>

This works perfect. The problem I am trying to figure out is how to display all post from all user when you are login as an administrator (on the front end)

I tried this but it then displays all of the post to all clients and administrator

 <?php if ( is_user_logged_in() ) : function filter_posts_by_author( $query ) { 
        global $current_user; get_currentuserinfo();
        $query->set( 'author, administrator', $current_user->ID );
      }
        add_action( 'pre_get_posts', 'filter_posts_by_author' );?> 

How would I go about displaying all post once an administrator is login and only display selected post when a user login?

Solutions Collecting From Web of "Display content based on a users login"

You could try this, IF the current user is logged in AND not Adminstrator it will pull all posts from the current user, otherwise it should default and show all posts from all users.

<?php 
    function filter_posts_by_author( $query ) {
        if( is_user_logged_in() ) {
            if( !current_user_can( 'administrator' ) ) {
                global $current_user; 
                get_currentuserinfo();
                $query->set( 'author', $current_user->ID );
            }
        }
        else {
            wp_die('Sorry, you do not have access to this page. Please <a href="/#/">sign in</a> to view this page.');
        }
    }
    add_action( 'pre_get_posts', 'filter_posts_by_author' );
?>