I’ve 3 hierarchical (category-like) customized taxonomies in a WP website, books
, characters
and writers
. I wish to create a dynamically populated dropdown menu of phrases for every of those within the website’s sidebar, in order that on choosing a time period in any of the dropdown the location routinely masses the corresponding archive.
Utilizing the strategy described right here I can get this engaged on one taxonomy solely. As quickly as I add extra I discover that solely the final one works.
Here is what I’ve thus far. Clearly I must discover a manner for later cases of the perform to not over-ride the sooner ones. I assumed that altering the IDs and performance names would do that nevertheless it’s clearly not that straightforward.
<?php
$writers = get_categories('taxonomy=writers');
$choose = "<select name='writers' id='writers' class='postform'>n";
$choose.= "<option value='-1'>Writers</option>n";
foreach($writers as $author){
if($writer->rely > 0){
$choose.= "<option value='".$writer->slug."'>".$writer->title."</option>";
}
}
$choose.= "</select>";
echo $choose;
?>
<?php
$characters = get_categories('taxonomy=characters');
$choose = "<select name='characters' id='characters' class='postform'>n";
$choose.= "<option value='-1'>Characters</option>n";
foreach($characters as $character){
if($character->rely > 0){
$choose.= "<option value='".$character->slug."'>".$character->title."</option>";
}
}
$choose.= "</select>";
echo $choose;
?>
<?php
$books = get_categories('taxonomy=books');
$choose = "<select name='books' id='books' class='postform'>n";
$choose.= "<option value='-1'>Books</option>n";
foreach($books as $ebook){
if($book->rely > 0){
$choose.= "<option value='".$book->slug."'>".$book->title."</option>";
}
}
$choose.= "</select>";
echo $choose;
?>
JS:
<script>
var dropdown = doc.getElementById("writers");
perform onWriterChange() {
if ( dropdown.choices[dropdown.selectedIndex].worth != -1 ) {
location.href = "<?php echo home_url();?>/writer/"+dropdown.choices[dropdown.selectedIndex].worth+"/";
}
}
dropdown.onchange = onWriterChange;
var dropdown = doc.getElementById("characters");
perform onCharacterChange() {
if ( dropdown.choices[dropdown.selectedIndex].worth != -1 ) {
location.href = "<?php echo home_url();?>/character/"+dropdown.choices[dropdown.selectedIndex].worth+"/";
}
}
dropdown.onchange = onCharacterChange;
var dropdown = doc.getElementById("books");
perform onBookChange() {
if ( dropdown.choices[dropdown.selectedIndex].worth != -1 ) {
location.href = "<?php echo home_url();?>/book/"+dropdown.choices[dropdown.selectedIndex].worth+"/";
}
}
dropdown.onchange = onBookChange;
</script>
Many thanks for any assist.