您可以使用OR
关系之后,您使用get_users()
函数获取您在查询中选择的所有用户。然后使用将其nicename输出到列表中foreach
.
$your_url = \'https://www.yoururl.com\';
$your_description = \'your description\';
$args = array(
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'user_url\',
\'value\' => $your_url,
\'compare\' => \'=\'
),
array(
\'key\' => \'description\',
\'value\' => $your_description,
\'compare\' => \'=\'
)
)
);
$users_array = get_users($args);
echo \'<ul>\';
if ($users_array ) {
foreach ($users_array as $user) {
echo \'<li>\'.$user->user_nicename.\'</li>\';
}
echo \'</ul>\';
} else {
echo \'nothing found\';
}
另一种方法是遍历所有用户,检查元值,如果值合适,只输出名称。缺点是您必须检查所有用户,如果用户很多,这可能需要一些时间。因此,我只是将此添加为一个补充,但建议使用元查询。
https://developer.wordpress.org/reference/functions/get_user_meta/
$users = get_users( array( \'fields\' => array( \'ID\',\'user_url\',\'user_nicename\',\'description\' ) ) );
foreach($users as $user){
$userurl = get_user_meta ( $user->user_url)); // all the values you need
if ( $userurl == $your_url ) { echo $user->user_nicename.\'<br>\'; }
// and so on
}
<小时/>
EDIT because of comment:
您可以通过将meta\\u键添加到$args数组来订购:
$args = array(
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'user_url\',
\'value\' => $your_url,
\'compare\' => \'=\'
),
array(
\'key\' => \'description\',
\'value\' => $your_description,
\'compare\' => \'=\'
),
),
\'orderby\' => \'user_url\'
);
这将适用于所有类型的字段,您只需要meta\\u键和order\\u by。下面是一篇关于如何使用它的好文章:
https://rudrastyh.com/wordpress/meta_query.html$args = array(
\'meta_key\' => \'license_id\',
\'orderby\' => \'meta_value\'
);
您还可以选择ASC或DESC顺序:
\'orderby\' => array(
\'license_id\' => \'ASC\'
),