marblecake
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [Advance WP Query Search Filter] Order taxonomies in drop down or check boxI had the same issues with checkboxes. Needed hierarchical taxonomy checkboxes, so edited taxcheckbox.php and replaced the foreach loop with this:
$parents = array(); $children = array(); foreach($terms as $term){ if($term->parent == 0){ $parents[] = $term; }else{ if(!isset($children[$term->parent])){ $children[$term->parent] = array(); } $children[$term->parent][] = $term; } } foreach($parents as $parent){ if(isset($_GET['taxo'][$c]['term'])){ if(is_array($_GET['taxo'][$c]['term']) ){ $selected = (isset($_GET['taxo'][$c]['term']) && in_array($parent->slug, $_GET['taxo'][$c]['term'])) ? 'checked="checked"' : '';} else{ $selected = (isset($_GET['taxo']) && $_GET['taxo'][$c]['term']==$parent->slug) ? 'checked="checked"' : ''; } } $value = $parent->slug; echo '<label class="taxcheckbox"><input type="checkbox" id="taxo-'.$c.'" name="taxo['.$c.'][term][]" value="'.$value.'" '.$selected.'>'.$parent->name.'</label>'; if(isset($children[$parent->term_id])){ echo '<ul class="taxcheck-children">'; foreach($children[$parent->term_id] as $child){ if(isset($_GET['taxo'][$c]['term'])){ if(is_array($_GET['taxo'][$c]['term']) ){ $selected = (isset($_GET['taxo'][$c]['term']) && in_array($child->slug, $_GET['taxo'][$c]['term'])) ? 'checked="checked"' : '';} else{ $selected = (isset($_GET['taxo']) && $_GET['taxo'][$c]['term']==$child->slug) ? 'checked="checked"' : ''; } } $value = $child->slug; echo '<li><label class="taxcheckbox"><input type="checkbox" id="taxo-'.$c.'" name="taxo['.$c.'][term][]" value="'.$value.'" '.$selected.'>'.$child->name.'</label></li>'; } echo '</ul>'; } }
Viewing 1 replies (of 1 total)