我不太确定这是您想要的(因为它太……简单了),但您需要做的只是在搜索表单中添加以下输入:
<input type="hidden" id="meta_key" name="meta_key" value="YOUR-META-KEY">
<input type="hidden" id="meta_value" name="meta_value" value="YOUR-META-VALUE">
或者,如果要手动触发搜索,请执行以下操作:
$search = new WP_Query(array(
\'s\' => \'YOUR-KEYWORD(S)\',
\'meta_key\' => \'YOUR-META-KEY\',
\'meta_value\' => \'YOUR-META-VALUE\'
));
// EDIT如果要处理更复杂的设置,可能需要使用
meta_query
:
$search = new WP_Query(array(
\'s\' => \'YOUR-KEYWORD(S)\',
\'meta_query\' => array(
\'key\' => \'YOUR-META-KEY\',
\'value\' => \'YOUR-META-VALUE\'
)
));
甚至
$search = new WP_Query(array(
\'s\' => \'YOUR-KEYWORD(S)\',
\'meta_query\' => array(
array(
\'key\' => \'YOUR-FIRST-META-KEY\',
\'value\' => \'YOUR-FIRST-META-VALUE\'
),
array(
\'key\' => \'YOUR-SECOND-META-KEY\',
\'value\' => \'YOUR-SECOND-META-VALUE\'
)
)
));