Custom taxonomy filter

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?

The easiest option according to me would be to pass a variable along with the URL and select the sub category based on that.

Second option is to get the URL and populate based on that. For example your url has the words /classification/the-constitution/ so for the constitution you could use the text and populate the sub categories as per the URL.

Thank you for the reply. So instead of checking to see if a query has already been done I should check to see if the URL slug is selected? How can I grab the correct URL slug to do this?

I was looking through my code more and testing it out on the link I posted http://www.constitutingamerica.org/dev2/. The first drop down box does not change which is what I want. The second box just clears its results. What I think is happening is that the second box is dependent on the $wp_query->get_queried_object_id(); variable I am grabbing to populate the second drop down. So when the second box is changed it is looking for children of the last query. To keep the results in the second box I need to grab the ID of the custom taxonomy that is selected in the first box. I have tried a bunch of different variables from the first half of the code that creates the first box but nothing seems to stick.

Any ideas on what I can grab from that first code to keep that second box populated with all of the child results?