在其当前形式中meta_query
是overwritten 在每次迭代中。最后,在中只有一个自定义字段meta_query
:
根据要使用的运算符,meta_query
参数应如下所示:
“的LIKE“,”REGEXP“”
if( is_array($keywords) && count($keywords) ) {
$args[\'meta_query\'] = array( \'relation\' => \'OR\' );
foreach( $keywords as $value )
{
$args[\'meta_query\'][] = array(
\'key\' => \'customfields\',
\'value\' => $value,
\'compare\' => \'REGEXP\', // or \'LIKE\'
);
}
}
// === result: ===
// $args[\'meta_query\'] = array(
// \'relation\' => \'OR\',
// [ \'key\' => \'customfields\', \'value\' => \'value_1\', \'compare\' => \'REGEXP\' ],
// [ \'key\' => \'customfields\', \'value\' => \'value_2\', \'compare\' => \'REGEXP\' ],
// [ \'key\' => \'customfields\', \'value\' => \'value_3\', \'compare\' => \'REGEXP\' ],
// );
“的
IN“”
if( is_array($keywords) && count($keywords) ) {
$args[\'meta_query\'] = array(
\'relation\' => \'OR\',
array(
\'key\' => \'customfields\',
\'value\' => $keywords,
\'compare\' => \'IN\',
)
);
}