Can I query user emails and custom fields at the same time? If I use SQL, it would be same as "Joint"
select *
from tblUser u
join tblCustomField cf where u.userid = cf.userid
Is below query correct?
$subscribed_emails = array("a@a.com", "b@b.com");
$args1 = array (
'search' => $subscribed_emails ,
'search_columns' => array( 'user_email' )
);
$args = array (
'meta_query' => array(
array(
'key' => 'wpcf-cf-user-red-grape-varieties2',
'value' => 'Shiraz'
)
)
);
$query1 = new WP_User_Query( $args1 );
$query2 = new WP_User_Query( $args2 );
$wp_user_query = new WP_User_Query();
$wp_user_query->results = array_merge( $query1->results,$query2->results );
Hello,
According to WP document:
https://codex.wordpress.org/Class_Reference/WP_User_Query#Search_Parameters
The "search" supports only one string value, does not support array value:
search (string) - Searches for possible string matches on columns.
So you can only search the result using one email address, for example:
$args = array (
'meta_query' => array(
array(
'key' => 'wpcf-cf-user-red-grape-varieties',
'value' => 'Shiraz1',
'compare' => 'LIKE'
)
),
'search' => 'a@a.com' ,
'search_columns' => array( 'user_email' )
);
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
...
How about key and value in meta_query? Can they be an array?
$args = array (
'meta_query' => array(
array(
'key' =>array("wpcf-cf-user-red-grape-varieties", "wpcf-cf-user-white-grape-varieties") ,
'value' =>array("Shiraz", "merlot")
'compare' => 'LIKE'
)
),
'search' => 'a@a.com' ,
'search_columns' => array( 'user_email' )
);
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
That is possible with WP_User_Query, for example:
$args = array (
'meta_query' => array(
array(
'key' => 'wpcf-cf-user-red-grape-varieties',
'value' => 'Shiraz1',
'compare' => 'LIKE'
),
array(
'key' => 'wpcf-cf-user-red-grape-varieties',
'value' => 'merlot',
'compare' => 'LIKE'
),
'relation' => 'OR',
),
'search' => 'a@a.com' ,
'search_columns' => array( 'user_email' )
);
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
More help:
https://codex.wordpress.org/Class_Reference/WP_User_Query#Custom_Field_Parameters
See the example codes in above document: "Multiple custom user fields handling"
please ignore this message
My issue is resolved now. Thank you!