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

    (@wp_dummy)

    For eg:

    add_filter('uwpqsf_tax_field_checkbox', 'customize_checkbox','',12);
    function customize_checkbox( $html ,$type,$exc,$hide,$taxname,$taxlabel,$taxall,$opt,$c,$defaultclass,$formid,$divclass){
      $eid = explode(",", $exc);//get the exclude term id in array
      $args = array('hide_empty'=>$hide,'exclude'=>$eid ); setup the arguments for get_terms use, you can change exclude to include if you want, or add any other get_terms parameters
    
      $terms = get_terms($taxname,$taxoargs); //get the terms
       $count = count($terms);
       if ( $count > 0 ){ //make sure the taxonomy has terms
            $html = ''; //clear the original checbox html
               //below out put the new checkbox html, you can customize it as you like, but there are various important element must present in the html, such as the hidden fields.
    
               $html  = '<div class="'.$defaultclass.' '.$divclass.' togglecheck" id="tax-check-'.$c.'"><span  class="taxolabel-'.$c.'">'.$taxlabel.'</span >';
    				$html .= '<input  type="hidden" name="taxo['.$c.'][name]" value="'.$taxname.'">';//this is must
    				$html .= '<input  type="hidden" name="taxo['.$c.'][opt]" value="'.$opt.'">';//this is must
    				if(!empty($taxall)){
    				$checkall = (isset($_GET['taxo'][$c]['call']) && $_GET['taxo'][$c]['call'] == '1'  ) ? 'checked="checked"' : '';
    				$html .= '<label><input type="checkbox" id="tchkb-'.$c.'-0" class="tchkb-'.$c.' chktaxoall" name="taxo['.$c.'][call]"  value="1" '.$checkall.'>'.$taxall.'</label>';
    				}
    				$i = 1;
    				foreach ( $terms as $term ) {
    				$value = $term->slug;
    				$checked = (isset($_GET['taxo'][$c]['term']) && in_array($value, $_GET['taxo'][$c]['term'])) ? 'checked="checked"' : '';
    				$html .= '<label><input type="checkbox" id="tchkb-'.$c.'-'.$i.'" class="tchkb-'.$c.'" name="taxo['.$c.'][term][]" value="'.$value.'" '.$checked.'>'.$term->name.'</label>';
    				$i++;
    				}
       }
    
    }

    Here are the meaning of the function paremters:
    $html = original checkbox html output.

    $type = the input type, in this case it is ‘checkbox’

    $exc = exclude terms id that configured in the search form

    $hide = boolean field, to hide or not to hide empty terms.

    $taxname = the taxonomy slug, use this when you want specify the customization on certain taxonomy only

    $taxlabel = the label of the input field

    $taxall = add search all option

    $opt = operation such IN , OR

    $c = counter for the filter

    $defaultclass = class of the filter

    $formid = the formid

    $divclass = if you have define your own class in the shortcode

    Thread Starter Landon

    (@landonbotis)

    Beautiful reply. I’ll give this a go.

    Thanks.

    Thread Starter Landon

    (@landonbotis)

    Fantastic. This works very well.

    One thing that is missing from the code example above is returning $html.

    Here is what I have:

    function customize_checkbox($html,$type,$exc,$hide,$taxname,$taxlabel,$taxall,$opt,$c,$defaultclass,$formid,$divclass) {
    
        $eid = explode(",", $exc);
        $args = array('hide_empty'=>$hide,'exclude'=>$eid );
        $terms = get_terms($taxname,$taxoargs); //get the terms
        $count = count($terms);
    
        if ( $count > 0 ){ //make sure the taxonomy has terms
            $html = ''; //clear the original checkbox html
    
            $html  = '<div class="'.$defaultclass.' '.$divclass.' togglecheck" id="tax-check-'.$c.'"><span  class="taxolabel-'.$c.'">'.$taxlabel.'</span >';
            $html .= '<input  type="hidden" name="taxo['.$c.'][name]" value="'.$taxname.'">';//this is must
            $html .= '<input  type="hidden" name="taxo['.$c.'][opt]" value="'.$opt.'">';//this is must
    
            if(!empty($taxall)){
                $checkall = (isset($_GET['taxo'][$c]['call']) && $_GET['taxo'][$c]['call'] == '1'  ) ? 'checked="checked"' : '';
                $html .= '<label><input type="checkbox" id="tchkb-'.$c.'-0" class="tchkb-'.$c.' chktaxoall" name="taxo['.$c.'][call]"  value="1" '.$checkall.'>'.$taxall.'</label>';
            }
    
            $i = 1;
    
            foreach ( $terms as $term ) {
                $value = $term->slug;
                $checked = (isset($_GET['taxo'][$c]['term']) && in_array($value, $_GET['taxo'][$c]['term'])) ? 'checked="checked"' : '';
                $html .= '<label><input type="checkbox" id="tchkb-'.$c.'-'.$i.'" class="tchkb-'.$c.'" name="taxo['.$c.'][term][]" value="'.$value.'" '.$checked.'>'.$term->name.'</label>';
                $i++;
            }
        } 
    
        return $html;
    
    }
    
    add_filter( 'uwpqsf_tax_field_checkbox', 'customize_checkbox', '', 12);
    Plugin Author TC.K

    (@wp_dummy)

    Oh yes, missed that.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hooks Example’ is closed to new replies.