WordPress resource site for WordPress Beginners with easy to understand WordPress tutorials for mastering the basics and beyond.

WordPress Guide

WordPress Guide

WordPress get user by id

  • Open functions.php file
function get_display_name($user_id) {
    if (!$user = get_userdata($user_id))
        return false;
    return $user->data->display_name;
$display_name = get_display_name($some_user_id);
echo $display_name;

How to get a User ID in WordPress

The purpose of the ID number is to identify a specific item in the WordPress database, in this case, the User ID number. To get the User ID, head over to your backend. Click on Users and then on All Users.

Find the user you want to get the User ID for and click on Edit. After the user’s profile opens, look for user_id=number in the URL. As for finding your own User ID, the process is almost the same.

Go to Users and click on All Users. You’ll find your own name in the authors’ list, as well as the number of posts you’ve written. Click on the post number and find your user id in the address bar, where it will be listed “author=number.” And that’s it.

Example 1: wp get logged in user id

	$user_id = get_current_user_id();

Example 2: get_the_id wordpress

function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    $post = get_post();
    return ! empty( $post ) ? $post->ID : false;

Example 3: wordpress get username

$current_user = wp_get_current_user();

Example 4: get wordpress id

echo get_the_ID();

Example 5: wordpress get user by id

$user_obj = get_user_by('id', 1);