You can get the current user ID with get_current_user_id( )
:
$user_id = get_current_user_id( );
The user ID can be used to get the userdata with get_userdata( )
:
$user_data = get_userdata( $user_id );
With that information you should be able to fetch the requested Post with WP_Query
.
For example (by users nicename):
$query = new WP_Query( 'author_name=rami' );
Combining this all together you can create something like:
if ( is_user_logged_in( ) ) {
$user_id = get_current_user_id( );
$user_data = get_userdata( $user_id );
$query = new WP_Query( 'author_name=" . $user_data->user_nicename );
if( $query->have_posts( ) ) {
while( $query->have_posts( ) ) {
$query->the_post( );
// The Loop
}
}
} else {
// A visitor
}
You can play a little bit with the code to get exactly one post with WP_Query
but you sure are a bit further down the road with this.