我创建了两个类别,即城市和制造商。
我添加了城市名称作为城市的子类别,添加了制造商名称作为制造商的子类别。
Example:
city
- newyork
- paris
Manufacturer
- BMW
- Audi
现在我需要在一个下拉列表中显示城市列表,在另一个下拉菜单中显示制造商。
现在,在选择城市和制造商的详细信息并点击搜索后,它应该会显示属于城市和制造商类别的帖子。
感谢
我写了这篇文章,它将解决您的问题。
<form method="get" action="" id="findresult">
<h2><?php _e( 'City' ); ?></h2>
<?php wp_dropdown_categories('show_option_none=Select City&name=city&child_of=43'); //43 is id of city category ?>
<h2><?php _e( 'Manufacturer' ); ?></h2>
<?php wp_dropdown_categories('show_option_none=Select Manufacturer&name=manufacturer&child_of=44'); //44 is id of manufacturer category ?>
<input type="submit" value="Search"/>
</form>
<?php
if (($_GET['city'] != -1) && ($_GET['manufacturer'] != -1)):
$query = new WP_Query(array('category__and' => array($_GET['city'],$_GET['manufacturer'])));
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
echo "<p>".the_title()."</p>";
echo "<p>".the_content()."</p>";
endwhile;endif;
endif;
?>