Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use the_author_meta to retrieve some links which users can set in their profile.

I set up extra profile fields and they are saving to the database.

On my author.php I have the following code.

<div class="user_social_icons"><a href="<?php the_author_meta('facebook'); ?>" class="facebook" title="Facebook"></a></div>

For some reason this appears not to be working.

Any idea to why that may be?

Cheers

share|improve this question
2  
What happens instead? Add debug information to your question. –  toscho May 20 '12 at 19:35
    
in what context is this code? is it inside The Loop? –  Beto Frega May 20 '12 at 20:31
    
at the moment there is no content in the html link tag - is that done with css? –  Michael May 20 '12 at 20:47
add comment

1 Answer

It's entirely possible that you are calling the_author_meta() from outside of your post loop in the author.php template in which case the above will not work.

Instead, you can use

  • get_the_author_meta('facebook') or...
  • get_the_author_meta('facebook', $user_id) where $user_id is the ID# of the current user/author.

To get the user ID you can do this;

<div class="user_social_icons">
    <a href="<?php $id = get_current_user_id(); get_the_author_meta('facebook`, $id); ?>" 
    class="facebook" title="Facebook"> ??NO TEXT TO CLICK??  </a>
</div>


Notice we assigned the variable $id = get_current_user_id(); and then pass that along to our get_the_author_meta function.

??NO TEXT TO CLICK?? is not an error - you literally have no text between your anchor tags for people to click which could be why you're not seeing anything.

Notes:

  • the_author_meta($field, $userID) - works inside & outside of loop / will echo values.
  • get_the_author_meta($field, $userID) - works inside & outside of loop / will return values.

** when inside the loop, the $userID does not need to be specified if you want the meta data for that post author, otherwise using the ID parameter in the loop allows you to get the specific user meta for which the ID you pass in.

Its not entirely necessary to specify the user_id parameter, unless you would like to grab the data of another user whom is not the current post author however as an added measure by passing that value along it may help you solve your issue. Both functions accept the user_id parameter by the way.

So to recap,

  • Check the context of where you are calling your function from, is it within the loop or outside of the loop? Depending upon where within your author.php template you are calling from, choose the appropriate function as described above. Optionally pass the user ID if you want to be doubly sure.

  • Check whether or not the fact you have no text <a href"#">between</a> you href anchor is in fact causing you the problem, unless you are injecting the link or styling the link/div with a width/height/background then this is the likely culprit and why you are not seeing anything.

share|improve this answer
    
the_author_meta also accepts a user ID-- optional second parameter. It is not a Loop only function, but must be used within the Loop that second parameter is not supplied. –  s_ha_dum May 18 '13 at 15:47
    
@s_ha_dum Yes thank you, I corrected my explanation, I meant to say that it does work in both thank you for pointing out the discrepancy. –  userabuser May 18 '13 at 19:06
add comment

Your Answer

 
discard

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.