echo '<form action=""><div class="row"><div class="small-12 medium-9 columns">';
echo michsci_get_terms_dropdown();
+
echo '</div><div class="small-12 medium-3 columns"><input type="submit" value="search" class="button"></div></div>';
echo '</form>';
function michsci_get_terms_dropdown()
{
- $myterms = get_terms('michsci_category', array(
- 'orderby' => 'name',
- 'hide_empty' => true
- ));
+ $taxonomyName = "michsci_category";
+
+ $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'name', 'hide_empty' => false));
+//
+//
+// $myterms = get_terms('michsci_category', array(
+// 'orderby' => 'id',
+// 'hierarchical' => 1,
+// 'hide_empty' => false
+// ));
$output ="<select name=\"michsci_category\"><option value=\"\">Select Category</option>";
- foreach ( $myterms as $term ) {
- $term_taxonomy = $term->taxonomy;
- $term_slug = $term->slug;
- $term_name = $term->name;
- $link = $root_url.'/'.$term_taxonomy.'/'.$term_slug;
- $output .= '<option value="' . $term->term_id . '"';
- if ($_REQUEST['michsci_category'] == $term->term_id) {
+
+// $term_name = $term->name;
+//
+// $term_taxonomy = $term->taxonomy;
+// $term_slug = $term->slug;
+// $term_name = $term->name;
+// $link = $root_url.'/'.$term_taxonomy.'/'.$term_slug;
+
+ // get parent categories
+ foreach ($parent_terms as $parent){
+ $term_name = $parent->name;
+ $term_taxonomy = $parent->taxonomy;
+ $term_slug = $parent->slug;
+ $term_name = $parent>name;
+ // get children of each category
+ $child_terms = get_terms($taxonomyName, array('child_of' => $parent->term_id, 'orderby' => 'name', 'hide_empty' => false));
+ $output .= '<option value="' . $parent->term_id . '"';
+ if ($_REQUEST['michsci_category'] == $parent->term_id) {
+ $output .= ' selected';
+ }
+ $output .= '>' . $parent->name . '</option>';
+ foreach($child_terms as $child){
+ $output .= '<option value="' . $child->term_id . '"';
+ if ($_REQUEST['michsci_category'] == $child->term_id) {
$output .= ' selected';
}
- $output .= '>' . $term_name . '</option>';
- }
+ $output .= '>' . "   " . $child->name . '</option>';
+
+ }
+ }
$output .="</select>";
return $output;
}