How to get user meta information in WordPress

No comments
Hello Friends, after a long break, I am back once again. Today I am going to share with you a very simple but useful small code for getting all logged in user's meta information. Although, this tutorial is already written on WordPress official site and many other tutorial/blog websites so that I thought, I must share this on my blog too. As we know, while developing a WordPress website sometimes we need to get all user meta information, for example, user first name, last name, etc. In this case, this small code will work for you like oxygen. So without taking too much time, let's start:

$user_meta = get_user_meta(get_current_user_id());

In above example the code will return all meta tags of logged in user and you can choose which one you want to display on your page. But if you want to get only one meta tag then you should use below code.

$user_last = get_user_meta( get_current_user_id(), 'last_name', true );

By using above code you will get logged in user's last name saved in database. In given example get_current_user_id() function will return current logged in user id.

Thank you for reading my post. Good Luck.

No comments :

Post a Comment