Wordpress:显示两个下拉列表中的类别,并显示两个下拉菜单中所选类别的常用帖子

时间:2015-02-20 10:06:55

标签: php wordpress categories

我创建了两个类别,例如城市和制造商。

我已将城市名称作为子类别添加到城市和制造商名称中作为制造商的子类别。

Example:
  city
   - newyork
   - paris
 Manufacturer
   - BMW
   - Audi

现在我需要在一个下拉列表中显示城市列表,在另一个下拉列表中显示制造商。

现在选择城市和制造商详细信息并点击搜索后,它应显示属于城市和制造商类别的帖子。

由于

1 个答案:

答案 0 :(得分: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;
?>
相关问题