I am now trying to create a profile page for the user and in this link the following appears
example.com/profile/peter
profile = page name
peter = username
But I also want when Peter sends The link at the top with his username shows Peter's information, not the current user's information
I want to get ID Peter when I enter the page so that I can extract his information inside that page D:
CodePudding user response:
Your question is not fully completed, and not sure how did you make your login authentication. But if I understand you, you want to get User ID from link? Than use $_GET
.
Example:
example.com/profile/id=1
/**
* Return the id. In this case it is going to return 1
*/
public function getId(): int
{
// This is going to get the ID from the bar, which is 1
$userId = $_GET['id']
return $userId;
}
CodePudding user response:
As much as i understand you want the ID of the user of current user page.
if you have author.php
in your theme you can add this code in there
if( get_query_var( 'author_name' ) ) {
$current_author = get_user_by( 'slug', get_query_var( 'author_name' ) );
} else {
$current_author = get_userdata( get_query_var( 'author' ) );
}
$current_author_id = $current_author->ID;
CodePudding user response:
variable user_id = the id inside url
this code only works if the ID inside the url in the following form ( profile?id=1 )
if (isset($_GET['id'])) {
$user_id = $_GET['id'];
}
echo $user_id;