I'm writing a code for author.php . I access this by: http://example.com/author/{user_nicename} Imagine there are some users (Including 1 Admin, 4 or 5 editors, and so on ...) Now when users click on above URL, They see their own Information. I want to give permission to Admin and Editors to see the other arbitrary users Information. How can i do that? This is a part of my code in author.php :

$user_id = get_current_user_id();
global $wpdb;
$result = $wpdb->get_results(" SELECT display_name 
                               FROM wp_introduction 
                               INNER JOIN wp_users 
                               ON costumer_id = ID 
                               WHERE $introducer_id = $user_id" );



Instead of using $user_id = get_current_user_id(), you want to get the ID of the author by doing something like

$author = get_user_by( 'slug', get_query_var( 'author_name' ) );


if ( $author= get_query_var( 'author' ) ) { $author = get_user_by( 'id', $author_id ); }

And then use like

 $user_id = $author->ID;

Source: https://wordpress.stackexchange.com/a/35251/47406

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.