我正在尝试:
<?php $phone = get_user_meta($current_user->ID,\'phone_number\',true); echo $phone; ?>
但它不起作用我正在尝试:
<?php $phone = get_user_meta($current_user->ID,\'phone_number\',true); echo $phone; ?>
但它不起作用<?php
// number 9 will be user ID
$all_meta_for_user = get_user_meta( 9 );
print_r( $all_meta_for_user );
// find the key that you want
Array (
[first_name] => Array ( [0] => Tom )
[last_name] => Array ( [0] => Auger)
[nickname] => Array ( [0] => tomauger )
[description] => etc....
)
// store it in a variable
$last_name = $all_meta_for_user[\'last_name\'][0];
// display it
echo $last_name;
如果不循环所有用户,只想获取当前用户phone_number
然后你可以试试下面的方法。
$current_user_id = get_current_user_id();
$phone = get_user_meta($current_user_id,\'phone_number\',true);
echo $phone;
NOTE: 这仅适用于已登录的用户。同时检查phone_number
meta\\u键。我想默认情况下wordpress没有这样的元键。
WordPress有一个获取当前用户ID的快捷方式,听起来您需要--get_current_user_id()
. 使用它,您应该能够获得所需的信息。以下是一个概念验证代码块,它将检查函数的返回值,并在需要时应用一些条件逻辑:
$uid = get_current_user_id();
if (!empty($uid)) {
$phone = get_user_meta($uid,\'phone_number\',true);
if (!empty($phone)) {
echo $phone;
} else {
echo \'User does not have a phone number stored in the database\';
}
} else {
echo \'User is not logged in\';
}
<?php $phone = get_user_meta($current_user->ID,\'phone\',true); echo $phone;?>
这是“电话”,而不是“电话号码”$phone = get_user_meta($user_id, \'billing_phone\', true);
echo $phone;
我正在使用带有动态文本插件的联系人表单7。这真的很好用。。。我所做的是将其设置为,如果用户单击产品上的链接,它会将他们重定向到查询表单,并且产品名称已经输入到字段中。。。使用以下CF7代码,这可以正常工作:<p>[dynamictext enquiry-product \"CF7_GET key=\'product-name\'\" ]</p> 然后通过以下方式导航到查询表单:http://www.myurl.com/contact-form/?product-name=