我使用以下代码隐藏并创建了各种配置文件字段:
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\');
然后,我尝试使用以下命令调用自定义字段:
<?php echo get_user_meta($current_user->ID,\'I work for...\',true);?>
这没什么意思,有人能给我指出正确的方向吗?
最合适的回答,由SO网友:birgire 整理而成
改为尝试
$user_contactmethods[\'work\'] = __(\'I work for...\');
以及
<?php echo get_user_meta($current_user->ID,\'work\',true);?>
其中数组索引为
\'work\'
而不是
\'I work for...\'
, i、 e.小写,无空格。