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've hidden and created various profile fields using the following code:

function my_user_contactmethods($user_contactmethods) {

// You can get rid of ones you don't want
unset($user_contactmethods['jabber']);
unset($user_contactmethods['yim']);
unset($user_contactmethods['aim']);
unset($user_contactmethods['googleplus']);
unset($user_contactmethods['url']);
unset($user_contactmethods['twitter']);

// And add any news ones. The array key is the meta key name, the text
// is however you want it labelled -- keep the key name the same as you have in gf map.

$user_contactmethods['I work for...'] = __('I work for...');

// etc for each field you want to appear

return $user_contactmethods;

}

add_filter( 'user_contactmethods', 'my_user_contactmethods');

I'm then trying to call the custom field using the following:

<?php echo get_user_meta($current_user->ID,'I work for...',true);?>

This doesn't show anything, can someone point me in the right direction?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Try instead

$user_contactmethods['work'] = __('I work for...');

and

<?php echo get_user_meta($current_user->ID,'work',true);?>

where the array index is 'work' instead of 'I work for...', i.e. lowercase and without any spaces.

share|improve this answer
    
I've just tried that, the info is getting inserted into the custom field but it still won't show on the front end. Is there another way to call it? –  Rob Mar 4 '13 at 11:16
    
It works on my vanilla wp install, I just tested it. I checked the profile.php page for the current user, and inserted some value and saved it. Then added the code on single.php to test. –  birgire Mar 4 '13 at 11:21
    
does this work for you: <?php echo "current userid:". $current_user->ID;?> –  birgire Mar 4 '13 at 11:23
    
It's in the header.php file, so outside of the loop, that's probably why it's not working. –  Rob Mar 4 '13 at 11:24
1  
ok add global $current_user; before the code. –  birgire Mar 4 '13 at 11:25
show 1 more 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.