WordPress.org

Ready to get started?Download WordPress

Forums

Ultimate WP Query Search Filter
Order Parent Child Categories as indented checkboxes (7 posts)

  1. paulwalker
    Member
    Posted 5 months ago #

    Hi,

    I'm using a parent and child category structure. I would like to display this on the search form so that the parent category is displayed and then the indented child categories are printed below - all as checkboxes.

    Such as

    Animals
    Dolphin
    Penguin

    Any Suggestions welcome

    https://wordpress.org/plugins/ultimate-wp-query-search-filter/

  2. paulwalker
    Member
    Posted 5 months ago #

    Sorry the list didn't display properly

    As Follows:

    Animals (Parent Category)
    --Dolphin (Child Category)
    --Penguin

  3. TC.K
    Member
    Plugin Author

    Posted 5 months ago #

    You can use 'uwpqsf_tax_field_checkbox' filter to customize the checkbox layout for taxonomy. But it could be complicated.

    The field using following script to generate the html field:

    $html  = '<div class="'.$defaultclass.' '.$divclass.' tax-check-'.$c.' togglecheck"><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 .= '<label><input type="checkbox" id="tchkb-'.$c.'" name="taxo['.$c.'][call]" class="chktaxoall" >'.$taxall.'</label>';
    				}
    				foreach ( $terms as $term ) {
    				$value = $term->slug;
    				$html .= '<label><input type="checkbox" id="tchkb-'.$c.'" name="taxo['.$c.'][term][]" value="'.$value.'" >'.$term->name.'</label>';
    				}
    				$html .= '</div>';

    As you can see there are essential part in the field such as the hidden fields and input name 'taxo['.$c.'][term][]'

    To use the filter:

    add_filter('uwpqsf_tax_field_checkbox','my_cus_check_display','',12);
    function my_cus_check_display($html ,$type,$exc,$hide,$taxname,$taxlabel,$taxall,$opt,$c,$defaultclass,$formid,$divclass){
    {
    //there are 12 parameters in the function, so you can refer to above default to customize what you want. eg.
    $eid = explode(",", $exc);
    $args = array('hide_empty' => $hide, 'orderby' => 'term_group','exclude'=>$eid ); // group the terms
    $terms = get_terms($taxname,$taxoargs);
    
    $html  = '<div class="'.$defaultclass.' '.$divclass.' tax-check-'.$c.' togglecheck"><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 .= '<label><input type="checkbox" id="tchkb-'.$c.'" name="taxo['.$c.'][call]" class="chktaxoall" >'.$taxall.'</label>';
    				}
    				foreach ( $terms as $term ) {
    				$value = $term->slug;
    				$html .= '<label><input type="checkbox" id="tchkb-'.$c.'" name="taxo['.$c.'][term][]" value="'.$value.'" >'.$term->name.'</label>'; //here is where you want to customize
    				}
    				$html .= '</div>';
    
    return $html;
    }
  4. paulwalker
    Member
    Posted 5 months ago #

    Hi TC.K,

    Thanks for responding. I'm currently trying to understand the code related to the changes you mentioned.

    I'm a bit confused as to which plugin files to add it to. Could you point me in the right direction?

    Much appreciated

  5. TC.K
    Member
    Plugin Author

    Posted 5 months ago #

    It's filter, so you can add it on your theme's functions.php

  6. paulwalker
    Member
    Posted 4 months ago #

    Hi TC.K,

    I've added the code you provided to the functions.php file but i'm a not sure as to why it's not working. Basically, only one category (uncategorised) displays even though I do not have any custom taxonomies.

    Any suggestions welcome,

    Paul

  7. TC.K
    Member
    Plugin Author

    Posted 4 months ago #

    Not sure what is it. But you can turn the wp debug on to see if there any errors.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.