I have this code and it's working, but the problem is that is loading the next category( there are 3 level categories
County
State
City
) VERY VERY slow, I think it needs some ajax, please help
<form action="<?php echo remove_query_arg(array('mycat_go', 'cat')); ?>" method="get">
<?php
// get selected category and do some initializations
if (isset($_REQUEST['cat'])) $_REQUEST['mycat_go'] = $_REQUEST['cat'];
$selected = $_REQUEST['mycat_go'];
$selects = array();
$last = 0;
$top = false;
$i = 0;
// basically, we are looping from the selected up through the parents
// till we have no parent anymore.
while (!$top) {
// prep query to generate field containing all child categories
// of the selected one
$args = array(
'name' => 'mycat_'.$i,
'orderby' => 'name',
'class' => selInput,
'echo' => 0,
'hierarchical' => 1,
'exclude' => '1,19',
'child_of' => $selected,
'depth' => 1,
'show_option_none' => '- Please select -',
'hide_if_empty' => true,
);
if(!empty($last)) $args['selected'] = $last;
// prepare next loop iteration or stop if we are displaying children of 0
if (!empty($selected)) {
$last = $selected;
$category = get_category($selected);
$selected = $category->parent;
} else {
$top = true;
}
// generate output and store in reversed order as we are going bottom up
$select = wp_dropdown_categories($args);
$select = preg_replace("#<option([^>]*)>#", "<option$1 onclick=\"this.parentNode.name = 'mycat_go';return this.form.submit()\">", $select);
array_unshift($selects, $select);
$i++;
}
// print to screen
foreach ($selects as $select) {
echo $select;
} ?> </form>
<form action="<?php remove_query_arg(array('mycat_go', 'cat')); ?>" method="get">
<input type="hidden" name="cat" value="<?php echo $_REQUEST['mycat_go']; ?>" />
<input type="image" src="<?php bloginfo('template_directory'); ?>/images/btn_put.png">
</form>