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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题