获取所选术语列表选择选项下拉列表

时间:2014-12-04 04:07:30

标签: wordpress

你能帮帮我吗? 我用wordpress
例: 我有分类:部门

  • 学期有帖子名称:心脏诊所(医生1,医生2,医生3)
  • 学期有帖子名称:妇科诊所(医生4,医生5)

我想要 当我选择Cardiac Clinic然后显示下拉

<select>
<option>doctor 1</option>
<option>doctor 2</option>
<option>doctor 3</option>
</select>


当我选择妇科诊所然后显示下拉

<select>
<option>doctor 4</option>
<option>doctor 5</option>
</select>

非常感谢你!

2 个答案:

答案 0 :(得分:0)

$post_type = 'event-posts';
$customPostTaxonomies = get_object_taxonomies($post_type);
if(count($customPostTaxonomies) > 0)
 {
  foreach($customPostTaxonomies as $tax)
  {
     $args = array(
          'orderby' => 'name',
          'show_count' => 0,
          'pad_counts' => 0,
          'hierarchical' => 1,
          'taxonomy' => $tax,
          'title_li' => ''
        );
        wp_dropdown_categories( $args ); 
  }
}

答案 1 :(得分:0)

我知道你有2个选择元素。第一:部门和第二部门:医生。您的代码结构与:

相同
<select id="dep" name="dep">
  <option value="">Select Department</option>
  <option value="?department={DEP_ID}" selected="selected">Cardiac Clinic</option>
  <option value="?department={DEP_ID2}" selected="selected">Gynaecological Clinic</option>
</select>

使用GET方法选择自动提交表单。你可以把它变成这个jQuery: 当然,你必须拥有jQuery Library。

<script>
    $(function(){
      $('#dep').bind('change', function () {
          var url = $(this).val();
          if (url) {
              window.location = url;
          }
          return false;
      });
    });
</script>

编辑此页面php源代码如下:

  $list = array();
  if(isset($_GET['department'])){
    // get your posts by term

    $args = array(
      'tax_query' => array(
        array(
          'taxonomy' => 'department',
          'field' => 'id',
          'terms' => $_GET['dep']
        )
      )
    );
    $postslist = get_posts( $args );

    foreach($postslist as $doctor)
      $list[] = array("ID" => $doctor->ID, "title" => $doctor->post_title );
      // add doctors to list
  } else {
    $list[] = array("ID" => 0, "title" => "Select department first");
  }