【问题标题】:Wordpress: Display categories in two drop down and display the posts that is common for the categories selected in both dropdownsWordpress:在两个下拉列表中显示类别并显示在两个下拉列表中选择的类别常见的帖子
【发布时间】:2015-02-20 10:06:55
【问题描述】:
我创建了两个类别,比如城市和制造商。
我已将城市名称添加为城市的子类别,并将制造商名称添加为制造商的子类别。
Example:
city
- newyork
- paris
Manufacturer
- BMW
- Audi
现在我需要在一个下拉列表中显示城市列表,在另一个下拉列表中显示制造商。
现在选择城市和制造商详细信息并单击搜索后,它应该会显示属于城市和制造商类别的帖子。
谢谢
【问题讨论】:
标签:
php
wordpress
categories
【解决方案1】:
我写了这个可以解决你的问题。
<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;
?>