从 WordPress 对象数组中获取数据? [英] Get data from WordPress object array?

查看:22
本文介绍了从 WordPress 对象数组中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取 WordPress 用户的价值.我正在尝试使用 get_users() wp 函数.如何从此数组对象中从 roles 键中获取 [ user role ] 值.我的php代码是

echo '

';var_dump(get_users());echo '</pre>';

什么返回下面的代码

 数组(4) {[0]=>对象(WP_User)#510(7){[数据"]=>对象(标准类)#506(10){[ID"]=>字符串(2)12"[用户登录"]=>字符串(4)演示"[user_pass"]=>字符串(34)$P$Bp7wAWdn9qAPehmbEVcGz7DGGjc.lm1"[user_nicename"]=>字符串(4)演示"[user_email"]=>字符串(18)演示@something.com"[user_url"]=>字符串(19)http://demouser.com"[用户注册"]=>字符串(19)2015-10-14 12:34:02"[user_activation_key"]=>string(45) "1444826043:$P$BT2rYlAjdNo5OqzG7U3CvZw/sdnFqE."[用户状态"]=>字符串(1)0"[显示名称"]=>string(9) "演示用户"}[ID"]=>整数(12)[大写"]=>数组(1){[新贡献者"]=>布尔(真)}[cap_key"]=>字符串(15)wp_capabilities"[角色"]=>数组(1){[0]=>字符串(15)new_contributor"}[全部大写"]=>数组(4){[阅读"]=>布尔(真)["edit_posts"]=>布尔(真)[删除帖子"]=>布尔(假)[新贡献者"]=>布尔(真)}[过滤器"]=>空值}

解决方案

阅读代码

roles[0];}?>

https://codex.wordpress.org/Function_Reference/get_users

I am trying the get the value of the WordPress user. I am trying with the get_users() wp function. How can I get the [ user role ] value form the roles key from this array object. my php code is

echo '<pre>';
var_dump(get_users());
echo '</pre>';

What return the below code

  array(4) {
      [0]=>
      object(WP_User)#510 (7) {
        ["data"]=>
        object(stdClass)#506 (10) {
          ["ID"]=>
          string(2) "12"
          ["user_login"]=>
          string(4) "demo"
          ["user_pass"]=>
          string(34) "$P$Bp7wAWdn9qAPehmbEVcGz7DGGjc.lm1"
          ["user_nicename"]=>
          string(4) "demo"
          ["user_email"]=>
          string(18) "demo@something.com"
          ["user_url"]=>
          string(19) "http://demouser.com"
          ["user_registered"]=>
          string(19) "2015-10-14 12:34:02"
          ["user_activation_key"]=>
          string(45) "1444826043:$P$BT2rYlAjdNo5OqzG7U3CvZw/sdnFqE."
          ["user_status"]=>
          string(1) "0"
          ["display_name"]=>
          string(9) "demo user"
        }
        ["ID"]=>
        int(12)
        ["caps"]=>
        array(1) {
          ["new_contributor"]=>
          bool(true)
        }
        ["cap_key"]=>
        string(15) "wp_capabilities"
        ["roles"]=>
        array(1) {
          [0]=>
          string(15) "new_contributor"
        }
        ["allcaps"]=>
        array(4) {
          ["read"]=>
          bool(true)
          ["edit_posts"]=>
          bool(true)
          ["delete_posts"]=>
          bool(false)
          ["new_contributor"]=>
          bool(true)
        }
        ["filter"]=>
        NULL
      }

解决方案

Read the codex

<?php
$blogusers = get_users();
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
    echo $user->roles[0];
}
?>

https://codex.wordpress.org/Function_Reference/get_users

这篇关于从 WordPress 对象数组中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆