如何从数组内的 WP_User 对象获取数据 [英] How to get data from the WP_User Object inside a array
问题描述
可能的重复:
能够在print_r() 的输出中看到一个变量,但不确定如何在代码中访问它
如何从该数组内的 WP_User 对象中提取 ID:
数组([0] =>大批([盖子] =>WP_用户对象([数据] =>标准类对象([ID] =>24[用户登录] =>约翰福[user_pass] =>$P$BP0Qa4[user_nicename] =>约翰-富[用户电子邮件] =>johnfoo@gmail.com[user_url] =>[用户注册] =>2012-10-10 11:16:24[user_activation_key] =>[用户状态] =>0[显示名称] =>约翰福)[ID] =>24[大写] =>大批([委员会] =>1)[cap_key] =>sa_wp_capabilities[角色] =>大批([0] =>委员会)[全部大写] =>大批([edit_posts] =>1[阅读] =>1[级别_1] =>1[级别_0] =>1[删除帖子] =>1[委员会] =>1)[过滤器] =>)[lid_rol] =>沃尔兹特))
我使用以下代码:
';foreach($values 作为 $value){foreach ($value['lid'] 作为 $liddata) {echo $liddata->ID;}//很高兴看到您正在使用的内容echo '';print_r($values);echo '</pre>';}回声'</ul>';}}}?>
它返回用户id,还有很多如下注意事项:
<块引用>注意:试图获取非对象的属性
有人可以帮我吗?
我觉得问题出在这里:foreach ($value['lid'] as $liddata) {
此时,$value['lid']
是 WP_User
对象本身,因此 foreach 最终会遍历 的所有属性WP_User
对象.
如果你去掉那个 foreach,你应该能够从 $value['lid']
直接访问对象的公共属性(例如 $value['lid']->ID
或 $value['lid']->roles[0]
).
希望有所帮助.
Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code
How do I pull the ID from the WP_User object inside this array:
Array
(
[0] => Array
(
[lid] => WP_User Object
(
[data] => stdClass Object
(
[ID] => 24
[user_login] => John Foo
[user_pass] => $P$BP0Qa4
[user_nicename] => john-foo
[user_email] => johnfoo@gmail.com
[user_url] =>
[user_registered] => 2012-10-10 11:16:24
[user_activation_key] =>
[user_status] => 0
[display_name] => John Foo
)
[ID] => 24
[caps] => Array
(
[commissie] => 1
)
[cap_key] => sa_wp_capabilities
[roles] => Array
(
[0] => commissie
)
[allcaps] => Array
(
[edit_posts] => 1
[read] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[commissie] => 1
)
[filter] =>
)
[lid_rol] => Voorzitter
)
)
And I use the following code:
<?php
$rows = get_field('commissie_lid');
if($rows)
{
foreach($rows as $row)
{
$values = get_field('commissie_lid');
if($values)
{
echo '<ul>';
foreach($values as $value)
{
foreach ($value['lid'] as $liddata) {
echo $liddata->ID;
}
// allways good to see exactly what you are working with
echo '<pre>';
print_r($values);
echo '</pre>';
}
echo '</ul>';
}
}
}
?>
It returns the user id, but also a lot of the following notices:
Notice: Trying to get property of non-object in
Can someone help me?
I think the problem is here: foreach ($value['lid'] as $liddata) {
At that point, $value['lid']
is the WP_User
object itself, so that foreach ends up iterating over all of the properties of the WP_User
object.
If you eliminate that foreach, you should be able to directly access the public properties of the object from $value['lid']
(e.g. $value['lid']->ID
, or $value['lid']->roles[0]
).
Hope that helps.
这篇关于如何从数组内的 WP_User 对象获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!