您没有构建meta_query
正确地这很接近,但不完全正确。
$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\',);
}
}
正如您所写的,您得到了:
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"
}
}
您需要:
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"
}
}