Home » Functions » get_user_meta

Function Name: get_user_meta

WordPress is a powerful content management system that offers a wide range of functions to developers. One of the most important functions in WordPress is get_user_meta(), which is used to retrieve metadata for a specific user.

Metadata is essentially additional information that is attached to a user profile. It can be used to store any type of information, such as a user’s location, preferences, or any other custom information that is important for your website. get_user_meta() helps you retrieve this information when you need it.

The function takes two parameters: the user ID and the name of the metadata key. If the key doesn’t exist, the function will return an empty string.

Here’s an example of how to use get_user_meta():

$user_id = 123;

// Retrieve user meta for the ‘location’ key $location = get_user_meta($user_id, ‘location’, true);

// Output the location value echo ‘User location: ‘ . $location;

In this example, we retrieve the ‘location’ metadata for the user with ID 123. The third parameter of the function is set to true, which means that we want to retrieve a single value rather than an array of values. Finally, we output the location value using echo.

Overall, get_user_meta() is a powerful function that can help you retrieve important user information for your WordPress website.

Learn More on

Register an account to save your snippets or go Pro to get more features.