You aren’t constructing the meta_query
correctly. It is close but not quite right.
$searchArray = array();
$searchArray = array('relation' => 'OR',); // here is the change
// loop over checked checkboxes
if(!empty($_POST['course_location'])) {
foreach($_POST['course_location'] as $check) {
// echo '<h1>'.$check.'</h1>';
$searchArray[] = array('key' => 'course_location','value' => $check,'compare' => 'LIKE',);
}
}
As you have it written you were getting:
array(3) {
[0]=>
array(1) {
["relation"]=>
string(2) "OR"
}
[1]=>
array(3) {
["key"]=>
string(15) "course_location"
["value"]=>
string(1) "a"
["compare"]=>
string(4) "LIKE"
}
[2]=>
array(3) {
["key"]=>
string(15) "course_location"
["value"]=>
string(1) "b"
["compare"]=>
string(4) "LIKE"
}
}
And you need:
array(3) {
["relation"]=>
string(2) "OR"
[0=>
array(3) {
["key"]=>
string(15) "course_location"
["value"]=>
string(1) "a"
["compare"]=>
string(4) "LIKE"
}
[1]=>
array(3) {
["key"]=>
string(15) "course_location"
["value"]=>
string(1) "b"
["compare"]=>
string(4) "LIKE"
}
}