dswwuo1223 2013-01-16 11:25
浏览 105
已采纳

使用wp_query显示所有用户的列表?

Is it possible to use wp_query to create a list of all the Wordpress users for a site and their data? If so, how?

I want to be able to list ALL the users (the site is open to new registrations) and all their details such as name, username etc as well as some custom meta's that I've added in the format:

function my_user_contactmethods($user_contactmethods) {

$user_contactmethods['Address'] = __('Address');
$user_contactmethods['Website'] = __('Website');
$user_contactmethods['Phone'] = __('Phone');
$user_contactmethods['Nationality'] = __('Nationality');
$user_contactmethods['Registering as'] = __('Registering as');
$user_contactmethods['Submit work'] = __('Submit work?');
$user_contactmethods['Attend'] = __('Attend?');
$user_contactmethods['Volunteer'] = __('Volunteer?');

// etc for each field you want to appear

return $user_contactmethods;

}

Or if there's another way to do it then I'm completely open.

  • 写回答

1条回答 默认 最新

  • doufendi9063 2013-01-16 11:40
    关注

    If you are okay with not using wp_query , you can use get_users and get_user_meta to retrieve list of all users and their custom data.

    For example,

    <?php
        $blog_id = 1; //blog id
        $str = 'blog_id='.$blog_id;
        $users = get_users($str);
        $list = array();
        $i=0;
        foreach ($users as $user) {
           $list[$i]['id']=$user->ID;
           $list[$i]['email']=$user->email;
           $list[$i]['custom-1']= get_user_meta( $$user->ID, 'custom-1', true );
           $i++;
        }
    
    ?>
    

    You can retrieve the fields that you want. Or you can just add all data and attach your custom fields with them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么