• Resolved redsentence

    (@redsentence)


    Hi there,

    I am using dropdowns to list my taxonomies on a filterable search page. There are some taxonomies which are parent/child, but in the drop down they are all listed with the same indentation. Is it possible to indent the children/preceed with a hyphen?

    For example what I get in the dropdown is:

    Parent
    Child1
    Child2
    Parent2
    Child1
    Child2

    But what I need is something like…

    Parent
    – Child1
    – Child2
    Parent2
    – Child1
    – Child2

    Many thanks in advance!

    https://www.ads-software.com/plugins/ultimate-wp-query-search-filter/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author TC.K

    (@wp_dummy)

    You can refer to this thread.

    Thread Starter redsentence

    (@redsentence)

    Thanks I have tried to get it to work for a dropdown but with no luck. Here is what I have tried:

    add_filter('uwpqsf_tax_field_dropdown','custom_select_output','',12);
    
    function custom_select_output($html,$type,$exc,$hide,$taxname,$taxlabel,$taxall,$opt,$c,$defaultclass,$formid,$divclass){
    
    $eid = explode(",", $exc);
    
    $args = array('hide_empty'=>$hide,'exclude'=>$eid, 'hierarchical' => true, 'parent' => 0 );
    
    $taxoargs = apply_filters('uwpqsf_taxonomy_arg',$args,$taxname,$formid);
    $terms = get_terms($taxname,$taxoargs); $count = count($terms);
    
        if($type == 'select'){
                    $html  = '<div class="jas '.$defaultclass.' '.$divclass.' tax-select-'.$c.'"><span class="taxolabel-'.$c.'">'.$taxlabel.'</span>';
    
                    $html .= '<input type="hidden" name="taxo['.$c.'][name]" value="'.$taxname.'">';
                    $html .= '<input type="hidden" name="taxo['.$c.'][opt]" value="'.$opt.'">';
    
                    if(!empty($taxall)){
                        $html .= '<select id="tdp-'.$c.'" class="tdp-class-'.$c.'" name="taxo['.$c.'][term]">';
                        $html .= '<option selected value="uwpqsftaxoall">'.$taxall.'</option>';
                    }
    
                    if ( $count > 0 ){
                        foreach ( $terms as $term ) {
                            $selected = $terms[0]->term_id;
                            $html .= '<option value="'.$term->slug.'">'.$term->name.'</option>';
    
                            $args = array(
                                'hide_empty'    => false,
                                'hierarchical'  => true,
                                'parent'        => $term->term_id
                            );
                            $childterms = get_terms($taxname, $args);
    
                            foreach ( $childterms as $childterm ) {
                                    $selected = $childterms[0]->term_id;
    
                                $html .= "<option value='".$childterm->slug."'".">-" . $childterm->name . '</option>';
    
                            }}
                         }
    
                         $html .= '</select>';
                         $html .= '</div>';
                         return  $html;
        }
    
    }
    Thread Starter redsentence

    (@redsentence)

    Ignore me I fixed it! It had to be

    if($type == 'dropdown'){

    not

    if($type == 'select'){

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Parent/child taxonomy terms’ is closed to new replies.