如中所述the documentation meta_value
, 如果未在元查询中使用,则需要是字符串。
通常,如果要基于多个元数据进行查询,则需要添加meta_query
论点但正如文件中所述value
:
仅当compare
是\'IN\'
, \'NOT IN\'
, \'BETWEEN\'
, 或\'NOT BETWEEN\'
.
自从NOT LIKE
不是其中之一,这意味着您需要添加多个NOT LIKE
带有AND
关系,如:
$query = new WP_Query( array(
\'post_type\' => \'estate\',
\'post_status\' => \'any\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'getrix_id\',
\'value\' => \'miogest_\',
\'compare\' => \'NOT LIKE\',
),
array(
\'key\' => \'getrix_id\',
\'value\' => \'oneclick_\',
\'compare\' => \'NOT LIKE\',
),
array(
\'key\' => \'getrix_id\',
\'value\' => \'gestifiaip_\',
\'compare\' => \'NOT LIKE\',
),
),
) );
然而,这是相当冗长的。更简单的方法是使用
NOT REGEXP
作为比较。这会让你通过
regular expression 对于以
miogest_
,
oneclick_
, 或
gestifiaip_
, 然后只返回那些不返回true的结果:
$query = new WP_Query( array(
\'post_type\' => \'estate\',
\'post_status\' => \'any\',
\'meta_key\' => \'getrix_id\'
\'meta_compare\' => \'NOT REGEXP\',
\'meta_value\' => \'^(miogest_|oneclick_|gestifiaip_)\',
) );