• I have a code snippet that is returning team members associated with each user. However, one problem that I am having is that it is showing my team members as I am the user who is logged in. For example, if im logged in as Joe Bloggs and on my profile, I can see my team members. However, when I go onto John Smith’s profile – it is still showing Joe Blogg’s team members.

    Here is my custom code snippet:

    add_shortcode( 'Team_Members', function () {
    	global $current_user;
    	global $current_user_manager;
    	global $wpdb;
    	global $details;
    	
    	$teammembers = '';
    	$teammembersnames = '';
    
    	$current_user = wp_get_current_user();
    	$current_user_manager =get_metadata( 'user', $current_user->ID, 'Manager', true );
    	
    	$sqlquery = "SELECT DISTINCT wp_users.ID, wp_users.display_name FROM wp_users, wp_usermeta WHERE wp_users.ID = wp_usermeta.user_id AND wp_usermeta.meta_key = 'Manager' AND wp_usermeta.meta_value = '$current_user_manager'";
    	
    	$usernames = array();
        $nameArray = array();
        $usernames = $wpdb->get_results($sqlquery);
        foreach ($usernames as $details) {
    	$teammembers .= $details->ID."- ". $details->display_name . "<Br>";;
    
    }
    	return "<strong>Team Members</strong>"."<Br>".$teammembers;
    });

    What I need to do is to retrieve the ID of the user of which page I am currently visiting and not logged in as. I can see the User’s ID in the URL but how can I retrieve that ?

    Thanks!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Retrieve ID of users page’ is closed to new replies.