Skip to content

Instantly share code, notes, and snippets.

@ellefsen
Created March 18, 2014 11:35
Show Gist options
  • Save ellefsen/9618353 to your computer and use it in GitHub Desktop.
Save ellefsen/9618353 to your computer and use it in GitHub Desktop.
searchform.php with tax-term filter
<form role="search" method="get" id="searchform" action="<?php bloginfo('home'); ?>">
<input type="text" value="" name="s" id="s" />
<?php
function get_terms_dropdown($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$selected = "selected";
$output ="<select><option selected='".$selected."'>Select a Category</option>'";
foreach($myterms as $term){
$term_taxonomy=$term->My_Taxnomy;
$term_slug=$term->slug;
$term_name =$term->name;
$output .="<option name='".$term_slug."'>".$term_name."</option>";
}
$output .="</select>";
return $output;
}
$taxonomies = array('My_Taxonomy');
$args = array('order'=>'ASC','hide_empty'=>true);
echo get_terms_dropdown($taxonomies, $args);
?>
<input type="submit" id="searchsubmit" value="Search" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment