尝试WP_User_Query, 类似于:
$term = get_queried_object();
$users = new WP_User_Query(array(
\'meta_key\' => \'your_meta_key\', // the key in which you store your terms
\'meta_value\' => (int)$term->term_id, // assuming you store term IDs
));
print_r($users->get_results());
根据您的输入进行更新:
$term = get_queried_object();
$user_query = new WP_User_Query(array(
\'role\' => \'subscriber\', // or whatever your target role is
\'meta_key\' => \'involvement\',
\'meta_compare\' => \'like\',
\'meta_value\' => $term->name, // or "%{$term->name}%" ?
\'fields\' => array(\'user_email\'), // if you only need the email
));
$users = $user_query->get_results();
foreach($users as $user)
echo get_avatar($user->user_email);
请注意,“like”查询可能会失败,如果您有两个名称相似的术语,如“abc def”和“abc”,则返回错误的用户-在第二种情况下,您也会得到具有“abc def”术语的用户。
唯一可靠的方法是让所有用户都拥有元数据(删除元参数并将“fields”更改为“all\\u with\\u meta”),然后检查meta是否与确切的术语匹配,但此查询非常昂贵。。。