尝试以下操作:将此代码放入搜索表单中:
<form method="get" id="searchform" action="<?php bloginfo(\'url\'); ?>/search">
<?php
$args = array(
\'public\' => true,
\'_builtin\' => false
);
$output = \'objects\';
$operator = \'and\';
$taxonomies = get_taxonomies( $args, $output, $operator );
$my_tax_array = array(\'your_taxonomy_name1\',\'your_taxonomy_name2\',); //make array of your taxonomies
echo "<select id=\'my_select_taxonomy\' name=\'my_select_taxonomy\'>";
echo "<option value=\'0\'>----</option>";
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
if (in_array($taxonomy->name, $my_tax_array)){
echo "<option value=\'{$taxonomy->name}\'>{$taxonomy->label}</option>";
}
}
}
echo "</select><br />";
?>
<input type="text" value="" name="search_field" id="search_field" />
<input type="submit" id="searchsubmit" value="Search" />
在您的搜索页面中:
<?php
$search_field = $_GET[\'search_field\'];
$my_select_taxonomy = $_GET[\'my_select_taxonomy\'];
$args = array(
\'post_type\' => \'post\',
\'tax_query\' => array(
array(
\'taxonomy\' => $my_select_taxonomy,
\'field\' => \'slug\',
\'terms\' => $search_field,
)
)
);
$query = new WP_Query( $args );
?>