added third level dropdown
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 19 Jan 2016 21:43:08 +0000 (16:43 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 19 Jan 2016 21:43:08 +0000 (16:43 -0500)
index.php

index e986a66..5d68dfc 100644 (file)
--- a/index.php
+++ b/index.php
@@ -482,7 +482,6 @@ function michsci_shortcode($atts)
 function michsci_get_terms_dropdown($cat_id)
 {
     $taxonomyName = MICHSCI_CATEGORY_NAME;
-    
     if($cat_id){
         $main = get_term($cat_id, MICHSCI_CATEGORY_NAME);
         $cats_child = get_term_children($cat_id, $taxonomyName);
@@ -499,25 +498,36 @@ function michsci_get_terms_dropdown($cat_id)
     } else {
         
     $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'name', 'hide_empty' => false));
+    $terms = get_terms($taxonomyName, array('orderby' => 'name', 'hide_empty' => false));
     $output ="<select id='categoryDropdown' name=\"" . MICHSCI_CATEGORY_NAME . "\"><option value=\"\">Select " . MICHSCI_CATEGORY_SINGLE . "</option>";
         // get parent categories
         foreach ($parent_terms as $parent){
             // get children of each category
-            $child_terms = get_terms($taxonomyName, array('child_of' => $parent->term_id, 'orderby' => 'name', 'hide_empty' => false));
+            $child_terms = get_terms($taxonomyName, array('parent'=> $parent->term_id, 'child_of' => $parent->term_id, 'orderby' => 'name', 'hide_empty' => false));
             $output .= '<option value="' . $parent->term_id . '"';
             if ($_REQUEST[MICHSCI_CATEGORY_NAME] == $parent->term_id) {
                 $output .= ' selected';
             }
             $output .= '>' . $parent->name . '</option>';
             foreach($child_terms as $child){
-                $grandchildren = get_terms($taxonomyName, array('child_of' => $child->term_id, 'orderby' => 'name', 'hide_empty' => false));
+                $grandchildren = get_terms($taxonomyName, array( 'child_of' => $child->term_id, 'orderby' => 'name', 'hide_empty' => false));
                  $output .= '<option value="' . $child->term_id . '"';
                 if ($_REQUEST[MICHSCI_CATEGORY_NAME] == $child->term_id) {
                     $output .= ' selected';
                 }
                 $output .= '>' . "&nbsp&nbsp&nbsp" .  $child->name . '</option>';
-            }
+                foreach($grandchildren as $gchild){
+                 $output .= '<option value="' . $gchild->term_id . '"';
+                    if ($_REQUEST[MICHSCI_CATEGORY_NAME] == $gchild->term_id) {
+                        $output .= ' selected';
+                    }
+                    $output .= '>' . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" .  $gchild->name . '</option>';
+                }
         }
+    }
+     
+  
     $output .="</select>"; }
     return $output;
 }