key
在元查询需要是字符串的情况下,不能向单个元查询传递多个键。您需要为每个键添加查询:
$filter = array(
\'post_type\' => \'request\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => $key1,
\'value\' => $search_value,
\'compare\' => \'LIKE\',
),
array(
\'key\' => $key2,
\'value\' => $search_value,
\'compare\' => \'LIKE\',
),
array(
\'key\' => $key3,
\'value\' => $search_value,
\'compare\' => \'LIKE\',
),
),
);
注意,我设置
\'relation\'
到
\'OR\'
因此,将为匹配任何键(而不是所有键)的帖子返回结果。如果需要结果来匹配所有键,请将其更改回
\'AND\'
.