I need to do is to create a filter based on this new taxonomy. I need to do this with drop down boxes.
Here is an example of my custom taxonomy will be:
- Artlcles
— Article 1
— Article 2
— Article 3 - Amendments
— Amendment 1
— Amendment 2
— Amendment 3
What I need is to have 2 drop down boxes. The first one will have all of the top level categories (Articles, Amendments, etc…) and then when one of those is selected it will populate/make appear a second drop down with all of the subcategories.
I have put the following code together and maybe someone can help me figure out the last piece of the puzzle. You can also see what is happening at the URL http://www.constitutingamerica.org/dev2/
<?php $args = array(
'show_option_all' => '',
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 1,
'child_of' => 0,
'parent' => 0,
'exclude' => '',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 1,
'tab_index' => 0,
'taxonomy' => 'classification',
'hide_if_empty' => false,
'walker' => ''
);
$tax_menu_items = get_categories( $args ); ?>
<form name="class-filter" method="get" >
<select name="class-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Select</option>
<? foreach ( $tax_menu_items as $tax_menu_item ): ?>
<option value="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"><?php echo $tax_menu_item->name; ?></option>
<?php endforeach; ?>
</select>
<?php
$sub_tax_id = $wp_query->get_queried_object_id();
if($wp_query->get_queried_object_id()) {
$args2 = array(
'show_option_all' => '',
'show_option_none' => '',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 1,
'child_of' => 0,
'parent' => $sub_tax_id,
'exclude' => '',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat2',
'id' => '',
'class' => 'postform',
'depth' => 1,
'tab_index' => 0,
'taxonomy' => 'classification',
'hide_if_empty' => true,
'walker' => ''
);
$tax_menu_items2 = get_categories( $args2 ); ?>
<select name="class-dropdown2" onchange="document.location.href=this.options[this.selectedIndex].value;" >
<option value="">Select</option>
<? foreach ( $tax_menu_items2 as $tax_menu_item2 ): ?>
<option value="<?php echo get_term_link($tax_menu_item2,$tax_menu_item2->taxonomy); ?>"><?php echo $tax_menu_item2->name; ?></option>
<?php endforeach; ?>
</select>
<? } ?>
</form>
The only thing I need to figure out is how to keep the second drop down menu populated once it has been selected. Any ideas?