是否可以使用WP用户查询创建复杂查询?
使用WP Meta Query,我们可以使用嵌套数组进行复杂查询,如:
$meta_query_args = array(
\'relation\' => \'OR\', // Optional, defaults to "AND"
array(
\'key\' => \'_my_custom_key\',
\'value\' => \'Value I am looking for\',
\'compare\' => \'=\'
),
array(
\'relation\' => \'AND\',
array(
\'key\' => \'_my_custom_key_2\',
\'value\' => \'Value I am looking for 2\',
\'compare\' => \'=\'
),
array(
\'key\' => \'_my_custom_key_3\',
\'value\' => \'Value I am looking for 3\',
\'compare\' => \'=\'
)
)
);
$meta_query = new WP_Meta_Query( $meta_query_args );
我不确定是否可以:
$user_query = new WP_User_Query($meta_query_args);
我看不到
codex 如果可能的话。
https://codex.wordpress.org/Class_Reference/WP_User_Query
这是我的实际阵列,它不工作:
Array
(
[relation] => AND
[0] => Array
(
[relation] => AND
[0] => Array
(
[fields] => ID
[key] => ville
[value] => INDRE
[compare] => LIKE
[type] => CHAR
)
[1] => Array
(
[fields] => ID
[key] => user_metiers
[value] => 297
[compare] => LIKE
[type] => CHAR
)
)
[1] => Array
(
[relation] => OR
[0] => Array
(
[fields] => ID
[key] => last_name
[value] => david
[compare] => LIKE
[type] => CHAR
)
[1] => Array
(
[fields] => ID
[key] => first_name
[value] => david
[compare] => LIKE
[type] => CHAR
)
)
)
最合适的回答,由SO网友:TrubinE 整理而成
$meta_query_args = array(
\'meta_query\' => array(
\'relation\' => \'OR\', // Optional, defaults to "AND"
array(
\'key\' => \'_my_custom_key\',
\'value\' => \'Value I am looking for\',
\'compare\' => \'=\'
),
array(
\'relation\' => \'AND\',
array(
\'key\' => \'_my_custom_key_2\',
\'value\' => \'Value I am looking for 2\',
\'compare\' => \'=\'
),
array(
\'key\' => \'_my_custom_key_3\',
\'value\' => \'Value I am looking for 3\',
\'compare\' => \'=\'
)
)
);
$meta_query = new WP_User_Query( $meta_query_args );
添加“meta\\u query”=>数组(..)