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

I am trying to show the profile fields (like AIM, Jibber) outside the loop. I managed to do that with

global $post;

the_author_meta( $field, $author_id );

But now, I can't put an image beside it if such a field exists. This works inside the loop, but not outside:

<?php if (get_the_author_meta('aim')) {
echo "

<div class=schrijver-socialmedia>
  <img src=http://blablabla.com/images/aim_icon.png /> 

"; } ?>

How do I get this image outside the loop and only if the field exists?

share|improve this question
up vote 0 down vote accepted

get_the_author_meta accepts two parameters

  • $field - Field name for the data item to be returned.
  • $userID - If a user ID is passed to the function, it will return data for the specified user ID.

So just pass the user ID or author ID eg:

 if (get_the_author_meta('aim',$author_id)) { ...
share|improve this answer
Worked. Thanks! – user1627363 May 28 '13 at 10:42

get_the_author_meta is a wrapper around get_user_meta, which is what you should use instead.

$value = get_user_meta( $user_id, $key, $single );

$single is a true or false value, if you want a single meta field, pass true. If you have multiple fields of the same name, pass false, and it will return an array instead.

Since you only have a single field, named aim, pass in true


$aim = get_user_meta( $author_id, 'aim', true );

Here $author_id is the user ID of the author/user you're querying.

To check if the user has an aim, check the $aim value. get_user_meta will return false if no meta of that key was found.

if ( $aim != false ) {
    // do stuff

But what if there is an aim field and that field is empty? Then we can make use of empty() to check both cases, resulting in:

$aim = get_user_meta( $author_id, 'aim', true );
if ( !empty( $aim ) ) {
    // do stuff

Then of course you could always pass in the author ID as the second parameter to get_the_author_meta

share|improve this answer
Thanks mate. Also a very clear answer. – user1627363 May 28 '13 at 10:43

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.