I have a search widget with a drop down populated with my custom taxonomies. I need one of the other input fields to only show when a certain taxonomy or its children are selected.
Before you say this is only a jquary question, please bare with me. I think I need to edit wp_dropdown_categories() with Walker_CategoryDropdown to add data-select="select1" in the tag.
I found this code that does what I want I just dont know how to implement it.
The HTML (Updated to reflect my code):
<form role="search" method="get" id="equipfilter" action="<?php bloginfo('url'); ?>/">
<fieldset>
<?php
$dropdown_args = array(
'taxonomy' => 'exc_equipment_cat',
'name' => 'exc_equipment_cat',
'show_count' => 1,
'orderby' => 'name',
'hierarchical' => true,
'echo' => 0,
'walker' => new Walker_SlugValueCategoryDropdown
);
/*
wp_dropdown_categories( $dropdown_args );
*/?>
<?php
$select = wp_dropdown_categories($dropdown_args);
$select = preg_replace("#<select([^>]*)>#", "<select$1 data-select='select1'>", $select);
echo $select;
?>
</fieldset>
<fieldset class="hidden" data-select="NOT SURE WHAT TO PUT HERE">
<legend>Kw Range:</legend>
<input type="text" name="kw_min" placeholder="min" value><br />
<input type="text" name="kw_max" placeholder="max" value>
</fieldset>
<fieldset>
<legend>Price Range:</legend>
<input type="text" name="pr_min" placeholder="from" value><br />
<input type="text" name="pr_max" placeholder="to" value>
</fieldset>
<input type="submit" id="filtersubmit" value="Search" />
</form>
The css:
.hidden {
display:none;
}
The jquery (Updated to where its working now when tested with my test category):
jQuery(function ($){
$(function(){
$('.postform').change(function() {
var selectData = $(this).attr("data-select");
var selectValue = $(this).val();
$('.hidden').hide();
if($("fieldset[data-select='" + selectData + selectValue +"']").css("display") == "none"){
$("fieldset[data-select^='" + selectData + "']").hide();
$("fieldset[data-select='" + selectData + selectValue +"']").show();
}
});
});
});
$ddp = wp_dropdown_pages(array( 'echo' => FALSE, // return the HTML instead of outputting it )); $ddp = preg_replace('~^<select[^>]*+>\s*~', '', trim($ddp)); // opening select tag $ddp = preg_replace('~\s*</select>$~', '', $ddp); // closing select tag
<?php $select = wp_dropdown_categories($dropdown_args); $select = preg_replace("#<select([^>]*)>#", "<select$1 data-select='select1'>", $select); echo $select; ?>
and changing the echo in my $dropdown_args to 0$('.hidden').hide();
to hide fieldset if required category was deselcted