我正在尝试编写用户搜索查询,我有位置和搜索关键字(用户名)
我需要搜索所有用户,姓氏或名字与搜索关键字匹配 指定地点 我的代码在这里,
$args = array(
'meta_query' => array(
'relation' => 'AND',
0 => array(
'key' => 'last_name',
'value' => $search_string,
'compare' => 'LIKE'
),
1 => array(
'key' => 'first_name',
'value' => $search_string,
'compare' => 'LIKE'
),
2 => array(
'key' => 'user_city',
'value' => $Location,
'compare' => 'LIKE'
),
),
);
$users = new WP_User_Query( $args);
$users = $users->get_results();
但我想要“关系”或名字和姓氏以及关系和位置,我该怎么做?
最佳答案
请使用
$args = array( 'meta_query' =>
array(
array(
'relation' => 'OR',
array( 'key' => 'last_name', 'value' => $search_string, 'compare' => 'LIKE' ),
array( 'key' => 'first_name', 'value' => $search_string, 'compare' => 'LIKE' ),
),
array( 'key' => 'user_city', 'value' => $Location, 'compare' => 'LIKE' ), ),
);
关于php - WordPress WP_User_Query 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23126485/