admin管理员组文章数量:1313182
I would like to write some arguments for my query and both need to be true. I am having trouble with the Syntax.
'meta_key' => $campaign_type,
'meta_value' => $Campaign_ID,
AND
'meta_key' => 'organisation',
'meta_value' => $userOrg,
Below is my query code:
$args = array (
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => $campaign_type,
'meta_value' => $Campaign_ID,
'compare' => '='
),
array(
'meta_key' => 'organisation',
'meta_value' => $userOrg,
'compare' => '='
)
));
Thank you.
I would like to write some arguments for my query and both need to be true. I am having trouble with the Syntax.
'meta_key' => $campaign_type,
'meta_value' => $Campaign_ID,
AND
'meta_key' => 'organisation',
'meta_value' => $userOrg,
Below is my query code:
$args = array (
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => $campaign_type,
'meta_value' => $Campaign_ID,
'compare' => '='
),
array(
'meta_key' => 'organisation',
'meta_value' => $userOrg,
'compare' => '='
)
));
Thank you.
Share Improve this question asked Sep 24, 2018 at 6:44 proteuscanvasproteuscanvas 235 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 0You have an example here: https://codex.wordpress/Class_Reference/WP_User_Query#Custom_Field_Parameters
Problem with your query is that you use wrong keys. It should be:
$args = array (
'meta_query' => array(
'relation' => 'AND',
array(
'key' => $campaign_type,
'value' => $Campaign_ID,
'compare' => '='
),
array(
'key' => 'organisation',
'value' => $userOrg,
'compare' => '='
)
));
Longer versions (meta_key
, meta_value
, meta_compare
) are used, when you don't use meta_query
but put them directly in the query.
$args = array(
'meta_key' => 'last_name',
's' => $_GET['search_text'],
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'name_organization', //ACF custom field
'value' => $text,
'compare' => 'LIKE'
),
array(
'key' => 'first_name', //User name
'value' => $text,
'compare' => 'LIKE'
),
)
);
$user_query = new WP_User_Query( $args );
本文标签: wp user queryWPUserQuery with 2 sets of conditions 39AND39
版权声明:本文标题:wp user query - WP_User_Query with 2 sets of conditions 'AND' 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741920568a2404985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
meta_query
withWP_User_Query
- just take a look at Codex ;) – Krzysiek Dróżdż Commented Sep 24, 2018 at 6:58