I want to display one dropdown menu with a list of values for a custom taxonomy. My taxonomy is "issue-year" and the dropdown would look like this:
<select name="issue-year">
<option value="#">Please select a year</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
</select>
Once a year is selected, a second dropdown would appear below the first to display posts in a custom post type that match the selected taxonomy value. My custom post type is "newsletter."
<select name="newsletter">
<option value="#">Please select an issue</option>
<option value="postname-1">Post Name 1</option>
<option value="postname-2">Post Name 2</option>
<option value="postname-3">Post Name 3</option>
</select>
I'm currently using "get_terms_dropdown" to generate the first field, but I'm not sure how to get from step one to step two. Also, if there's a better way than what I did in the code below I'd love to hear it.
function get_terms_dropdown($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$output ="<select name='issue-year'>";
$output .="<option value='#'>Please select a Year</option>";
foreach($myterms as $term){
$root_url = get_bloginfo('url');
$term_taxonomy=$term->taxonomy;
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$output .="<option value='".$link."'>".$term_name."</option>";
}
$output .="</select>";
return $output;
}