Title: Display Current User
Last modified: August 31, 2016

---

# Display Current User

 *  Resolved [lljb3](https://wordpress.org/support/users/lljb3/)
 * (@lljb3)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/)
 * Is it possible to display a current user’s player or staff profile information
   on a template page or page editor with shortcodes?
 * Basically I’m trying to create a profile template page since there will be multiple
   users logged in as either a player or a staff member, and that template page 
   needs to be able to display the current user’s connected player information or
   staff information.
 * The shortcodes force you to choose which player or staff member and **I want 
   to see if I can generate that player’s ID corresponding to the current logged
   in user ID with either PHP in the template or if there’s a shortcode to put in
   the page editor**. I’m not seeing too much PHP information in the template pages
   to help crack this.
 * Any help as soon as possible on this will be greatly appreciated!
 * [https://wordpress.org/plugins/sportspress/](https://wordpress.org/plugins/sportspress/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Roch](https://wordpress.org/support/users/rochesterj/)
 * (@rochesterj)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451374)
 * Hi there!
 * For this you’ll need to create a custom page template. Something like this: [https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/](https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/)
 * In your page template you’ll be able to use some PHP code to get the current 
   user ID, then send it to the shortcode. The magic will be done with the do_shortcode
   WP function: [https://developer.wordpress.org/reference/functions/do_shortcode/](https://developer.wordpress.org/reference/functions/do_shortcode/)
 * So all you need to do is to generate the shortcode text on the fly (using the
   ID) and send it to that function!
 * Kind Regards,
    -Roch
 *  Thread Starter [lljb3](https://wordpress.org/support/users/lljb3/)
 * (@lljb3)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451417)
 * Right, I already created the page template and the shortcode will only work with
   a specific ID at a time. I’m not seeing where I can pull the current player ID
   information that is connected to the currently logged in user.
 *  Thread Starter [lljb3](https://wordpress.org/support/users/lljb3/)
 * (@lljb3)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451418)
 * The current player ID and the current logged in user ID values are not the same.
 *  Thread Starter [lljb3](https://wordpress.org/support/users/lljb3/)
 * (@lljb3)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451420)
 * Ok, so I’m fairly close. I’m able to set parameters in which if a user is logged
   in and has a player or staff role to show the player or staff member post the
   user is connected to. I’m now having trouble figuring out how to call the post
   meta and terms to display the photo, stats, and player information. Any assistance
   to that would be greatly appreciated.
 * Here’s a sample of the code for if a user has a player role and player post set
   up:
 *     ```
       <?php elseif ( is_user_logged_in() && current_user_can('sp_player') ): ?>
                   <div class="row">
       				<?php
       					global $current_user;
       					get_currentuserinfo();
       					$author_query = array(
       						'posts_per_page' => '-1',
       						'author' => $current_user->ID,
       						'post_type' => 'sp_player'
       					);
       					$author_posts = new WP_Query($author_query);
       					while($author_posts->have_posts()) : $author_posts->the_post();
       				?>
                       <div class="col-md-4" id="left-sidebar">
                       	<div class="player-thumbnail"></div>
                       <!-- end .col-md-4 --></div>
                       <div class="col-md-8" id="right-sidebar">
                       	<h2 class="has-title"><?php the_title(); ?></h2>
                           <div class="player-info">
   
                           <!-- end .player-info --></div>
                           <div class="player-stats">
   
                           <!-- end .player-stats --></div>
                       <!-- end .col-md-8 --></div>
                       <?php endwhile; ?>
                   <!-- end .row --></div>
       ```
   
 * I’ve tried simple PHP calls like `<?php the_content(); ?>` and `<?php the_post_thumbnail?
   >` to no avail. I just need to print that information in the different spots 
   and I’m all set.
 *  [Roch](https://wordpress.org/support/users/rochesterj/)
 * (@rochesterj)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451453)
 * Hi!
 * I see what you mean now. It looks like you’ve got quite far there! Helping with
   this would be a bit out of our scope though, unfortunately. The player data is
   set in the custom post type, so the thumbnail is the right function, but you 
   need to get the right post ID and create a loop there for this
 * Kind Regards,
    -Roch
 *  Thread Starter [lljb3](https://wordpress.org/support/users/lljb3/)
 * (@lljb3)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451454)
 * Actually, I was able to figure it out. I found a thread deep in previous forum
   posts for this plugin’s support that linked the SportsPress API functions. I 
   was able to echo every portion I needed thanks to this list. If anyone else comes
   across this thread, firstly here’s the link to SportsPress’s API functions located
   in their Github (and in the plugin’s includes folder):
 * [https://github.com/ThemeBoy/SportsPress/blob/master/includes/sp-api-functions.php](https://github.com/ThemeBoy/SportsPress/blob/master/includes/sp-api-functions.php)
 * All you need to do is echo the function you want to display, for example:
    `<?
   php echo sp_get_player_number($id); ?>`
 * You can replace $id with $post->ID if it gets confusing. You also need to declare
   a new call, such as `$player = new SP_Player($id);`
 * I’ll post my example if anyone needs it.
 *     ```
       <?php elseif ( is_user_logged_in() && current_user_can('sp_player') ): ?>
                   <div class="row">
       				<?php
       					$current_user = get_current_user_id();
       					$id = get_the_ID();
       					$player = new SP_Player($id);
       					$author_query = array(
       						'posts_per_page' => '-1',
       						'author' => $current_user,
       						'post_type' => 'sp_player'
       					);
       					$author_posts = new WP_Query($author_query);
       					while($author_posts->have_posts()) : $author_posts->the_post();
   
       				?>
                       <div class="col-md-4" id="left-sidebar">
                       	<div class="player-thumbnail"><?php echo sp_player_photo($id); ?></div>
                           <div class="player-">
                               <?php wp_nav_menu(
                                   array(
                                       'theme_location' => 'primary',
                                       'container'      => 'ul',
                                       'menu_class'     => 'navbar-nav nav',
                                       'echo'           => true,
                                       'link_before'    => '<span>',
                                       'link_after'     => '</span>',
                                       'items_wrap'     => '<ul class="navbar-nav nav">%3$s</ul>',
                                       'depth'          => 0,
       								'walker'		 => new wp_bootstrap_navwalker()
                                   )
                               ); ?>
                           <!-- end .player- --></div>
                       <!-- end .col-md-4 --></div>
                       <div class="col-md-8" id="right-sidebar">
                       	<h2 class="has-title"><?php the_title(); ?></h2>
                           <div class="player-info">
                           	<?php echo sp_get_player_number($id); ?>
       						<?php echo sp_player_details($id); ?>
                           <!-- end .player-info --></div>
                           <div class="player-stats">
                           	<?php sp_player_statistics($id); ?>
                           <!-- end .player-stats --></div>
                       <!-- end .col-md-8 --></div>
                       <?php endwhile; ?>
                   <!-- end .row --></div>
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Display Current User’ is closed to new replies.

 * ![](https://ps.w.org/sportspress/assets/icon-256x256.png?rev=1252005)
 * [SportsPress - Sports Club & League Manager](https://wordpress.org/plugins/sportspress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sportspress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sportspress/)
 * [Active Topics](https://wordpress.org/support/plugin/sportspress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sportspress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sportspress/reviews/)

## Tags

 * [Profile Page](https://wordpress.org/support/topic-tag/profile-page/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [staff](https://wordpress.org/support/topic-tag/staff/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 6 replies
 * 2 participants
 * Last reply from: [lljb3](https://wordpress.org/support/users/lljb3/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/display-current-user/#post-7451454)
 * Status: resolved