The WHickster
The WHickster

Reputation: 3

Multiple values in meta_key query

I have a variable that looks like this

$the_vacancies_industry_areas_list = 'Call Centre','Child Care','Cleaning'

And i want to find if just one of these variables satisfies this case in a meta query

array(
'key' => 'industry_areas_list',
'value' => $the_vacancies_industry_areas_list,
'compare' => 'LIKE',


),

It only seems to satisfy if all three areas are present, not just one.

I want someone with just 'Child Care' or 'Cleaning' for example.

Upvotes: 0

Views: 3695

Answers (2)

vrajesh
vrajesh

Reputation: 2942

Try this: I made $the_vacancies_industry_areas_list as array variable and pass into wp_query

$the_vacancies_industry_areas_list = array('Call Centre','Child Care','Cleaning');

$args = array(
 'post_type' => 'YOUR_POST_TYPE',  //Set your post_type
 'post_status' => 'publish',  //Set your post_status
 'meta_query' => array(
  array(
   'key' => 'industry_areas_list',
   'value' => $the_vacancies_industry_areas_list,
   'compare' => 'IN'
  ),
 ),
);

Upvotes: 0

doublesharp
doublesharp

Reputation: 27609

You need to set the relation type on the wp_query args to OR, then define each of the OR conditions as arrays.

$args = array(
  'meta_query'     => array(
    'relation'  => 'OR',
     array (
       'key'     => 'industry_areas_list',
       'value'   => 'Call Centre',
       'compare' => 'LIKE'
     ),
     array (
       'key'     => 'industry_areas_list',
       'value'   => 'Child Care',
       'compare' => 'LIKE'
     ),
     array (
       'key'     => 'industry_areas_list',
       'value'   => 'Cleaning',
       'compare' => 'LIKE'
     )
);

Upvotes: 2

Related Questions