WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the user profile in Dashboard I have a section 'Contact info' containing email, URL, aim, yahoo, jabber. I would like to build a widget and output that user info within the widget. What function should I use to get just the contact info of a user?

share|improve this question
FYI: There's the Codex function reference and QueryPosts.com... – kaiser Oct 4 '12 at 6:36
I know that, my question is more specific. – drtanz Oct 4 '12 at 7:27
"(...) What function should I use to get just the contact info of a user?" ... what is more specific here? I read your comment ↓ below. Why don't you add that info in your question from the beginning? With 109 questions I'm pretty sure you know how to ask a complete question. – kaiser Oct 4 '12 at 7:46
@drtanz what research did you perform before asking this question? what have you tried already? – anu Oct 4 '12 at 7:51
I've checked get_user_meta() and get_userdata(). I also found _wp_get_user_contactmethods(). – drtanz Oct 4 '12 at 11:08
up vote 3 down vote accepted

It sounds like you're after the get_userdata() function.

As a basic example, you could retrieve a users email like this:

  if ( $user_id ) {
     $user = get_userdata($user_id);

     echo 'Users Email is: ' . $user->user_email;
share|improve this answer
So it isn't possible to get the fields of the contact info section automatically, without specifying them? My idea is to have email and url which are usually visible via get_userdata(), and also the social accounts like jabbar which are retrievable via get_user_meta(). The idea is to enable the user to add more accounts like 'skype' and have the widget be able to retrieve also these accounts without modification. – drtanz Oct 4 '12 at 7:27

If you allow the user to arbitrarily add accounts without knowing what those accounts are up front you leave yourself open to problems.

Say you have a meta_key for the user called user_custom_social and you provide a form that allows the user to add accounts such as,

Network Name                    URL
-------------------             ----------
facecrooks             --->     http://www.facecrooks.crooks/bob
mysocialwasteoftime    --->     http://www.mysocialwasteoftime.com/bob

Assume this user can't spell and as above spells Facebook as Facecrooks. When you iterate over these custom results the output will be erroneous.

If you also choose to display this information elsewhere, then the same erroneous information will be displayed.

To retrieve the values, you would do,

$meta = get_user_meta($user_id, $meta_key);
foreach ($meta as $key => $value){
echo $key . '=>' . $value;

Your best approach would be to define the social networks first so they can choose from a list.

Even if you decide to create a new meta_key per entry you are still going to be faced with the same problems of user input errors.

I would define my own list of social networks in a drop down with a input text field for their URL and then use,

The values you would get from the $_POST object except the $user_id,

$meta_key   = $_POST['network']; //will match the value selected from the drop down
$meta_value = $_POST['url']      //user entered input


add_user_meta($user_id, $meta_key, $meta_value); 

To display its the same deal,

$meta = get_user_meta($user_id, $meta_key);
foreach ($meta as $key => $value){
echo $key . '=>' . $value;
share|improve this answer
What's the deal with down voting an answer without providing feedback as to why? This answer addresses the question & the comment located here. Down votes on answers that are plausible solutions are meaningless. It ain't about no rep, its all about the solution, ya get me? – userabuser Oct 8 '12 at 8:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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