0

I am trying to get all those users having role as candidate and 3 skills as follows. skill a, skill x, skill e. Only want three users, What I am missing

$args = array(

    'role' => 'candidate',
    'meta_query' => array(
    'relation' => 'AND',
    array(
    'key' => 'as_skills',
    'value' => array('skilla','skillx','skille'),
    'compare' => '='
       ),
     ),
 );

$test = get_users($args);   


echo "<pre>";
print_r($test);
echo "</pre>";

getting no data, but data is there for sure.

3
  • According to codex: value (string|array) - Custom field value. It can be an array only when compare is 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN'. Also, do all candidate users have all the 3 "skill"?
    – Paul G
    Nov 6, 2017 at 7:26
  • what should I do for value in this situation ?
    – mohsin
    Nov 6, 2017 at 7:39
  • for the candidates only want those who has any one of these skills, and they are stored in json form in meta value
    – mohsin
    Nov 6, 2017 at 7:40

1 Answer 1

0

There is one small issue. You have to user 'IN' instead of = because you want to check values with array

$args = array(

    'role' => 'candidate',
    'meta_query' => array(
    'relation' => 'AND',
    array(
    'key' => 'as_skills',
    'value' => array('skilla','skillx','skille'),
    'compare' => 'IN'
       ),
     ),
 );

$test = get_users($args);   


echo "<pre>";
print_r($test);
echo "</pre>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.