title: Order Custom Taxonomy by Slug in Wordpress Plugin
body: <p><strong>CONTEXT</strong></p>
  
  <p>We have created a custom taxonomy that is to be displayed as a search filter parameter in third party plugin (in the form of a checkbox). However, we want the list of taxonomies to be displayed ordered by slug.</p>
  
  <p>This is the function that generates the checkbox and outputs the taxonomy - the part that we customized starts at " //create the attributes" . </p>
  
  <pre><code>public function checkbox($args)
  {
     //init defaults &amp; vars
     $input_args = $this-&gt;prepare_input_args($args, "checkbox");
  
     $input_name = $input_args['attributes']['name'];
     unset($input_args['attributes']['name']);
  
     //filter the input arguments before the html is generated - allowing almost all options to be modified
     if(has_filter('sf_input_object_pre')) {
        $input_args = apply_filters('sf_input_object_pre', $input_args, $this-&gt;sfid);
     }
  
     //prepare html
     $attibutes_html = $this-&gt;convert_attributes_to_html($input_args['attributes']);
  
     $open_child_count = 0;
  
     ob_start();
  
     ?&gt;
     &lt;ul&lt;?php echo $attibutes_html; ?&gt;&gt;
  
        &lt;?php
  
        $last_option_depth = 0;
  
        $option_count = count($input_args['options']);
        $current_depth = 0;
  
        $is_li_open = array();
        //echo "&lt;ul&gt;";
        for($i=0; $i&lt;$option_count; $i++)
        {
           $option = &amp;$input_args['options'][$i];
  
           if(!isset($option-&gt;attributes))
           {
              $option-&gt;attributes = array(
                 'class' =&gt; '',
                 'id'   =&gt; ''
              );
           }
           //check a default has been set and set it
           $option-&gt;attributes['type'] = "checkbox";
           $option-&gt;attributes['value'] = $option-&gt;value;
           $option-&gt;attributes['name'] = $input_name;
           $option-&gt;attributes['html'] = '';
  
           $container_attributes = array();
  
           if($this-&gt;is_option_selected($option, $input_args['defaults']))
           {
              $option-&gt;attributes['checked'] = 'checked';
              $option-&gt;attributes['class'] = trim($option-&gt;attributes['class']).' sf-option-active';
           }
           else
           {
              if(isset($option-&gt;attributes['checked']))
              {
                 unset($option-&gt;attributes['checked']);
              }
           }
  
           //now we want to put the class attribute on the LI, and remove from input
           $option_class = $option-&gt;attributes['class'];
           $option-&gt;attributes['class'] = $input_args['input_class'];
  
           $input_id = $this-&gt;generate_input_id($input_name."_".$option-&gt;value);
           $option-&gt;attributes['id'] = $input_id;
  
           $container_attibutes_html = "";
           if(isset($option-&gt;count))
           {
              $container_attributes['data-sf-count'] = $option-&gt;count;
  
              $container_attibutes_html = $this-&gt;convert_attributes_to_html($container_attributes);
  
           }
  
  
  
           //create the attributes
           $input_attibutes_html = $this-&gt;convert_attributes_to_html($option-&gt;attributes);
           $option_label = $option-&gt;label;
           $option_html = $option-&gt;attributes['value'];
  
           if($input_name == "_sft_module_authors[]"){
              $tax_name = "module_authors";
           } else if ($input_name == "_sft_module_mindset[]") {
              $tax_name = "module_mindset";
           } else if ($input_name == "_sft_module_language[]") {
              $tax_name = "module_language";
           } else if ($input_name == "_sft_management_levels[]") {
              $tax_name = "management_levels";
           } else{
              $tax_name = "wpdmcategory";
           }
  
              // Get the ID of a given category
           $my_term = get_term_by('slug',$option-&gt;value,$tax_name);
  
           $category_id = $my_term-&gt;term_id;
           $category_desc = $my_term-&gt;description;
           $category_name = $my_term-&gt;name;
           $meta_image = get_wp_term_image($category_id);
  
           // Get the URL of this category
           $category_link = get_category_link( $category_id );
  
  
  
  
           if ($input_name == "_sft_module_authors[]") {
  
              echo '&lt;li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'&gt;&lt;input '.$input_attibutes_html.'&gt;&lt;label class="sf-label-checkbox" for="'.$input_id.'"&gt;' . $category_name . '&lt;/label&gt;&lt;a class="eModal-post-'.$category_id.'" href="'.$category_link.'"&gt;&lt;i class="fa fa-info-circle"&gt;&lt;/i&gt;&lt;/a&gt;';
  
              echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "&lt;div class='col-md-8'&gt;" . $category_desc . "&lt;/div&gt;" . "&lt;div class='col-md-4'&gt;" .  "&lt;div class='img-wrap'&gt;&lt;img src='".$meta_image."'&gt;&lt;/div&gt;&lt;/div&gt;" . "[/modal]");
  
  
  
           } else if ($input_name == "_sft_module_mindset[]") {
  
              echo '&lt;li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'&gt;&lt;input '.$input_attibutes_html.'&gt;&lt;label class="sf-label-checkbox" for="'.$input_id.'"&gt;' . $category_name . '&lt;/label&gt;&lt;a class="eModal-post-'.$category_id.'" href="'.$category_link.'"&gt;&lt;i class="fa fa-info-circle"&gt;&lt;/i&gt;&lt;/a&gt;';
  
              echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "&lt;div class='col-md-12'&gt;" . $category_desc . "&lt;/div&gt;" . "[/modal]");
  
  
  
           } else if  ($input_name == "_sft_module_language[]") {
  
              echo '&lt;li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'&gt;&lt;input '.$input_attibutes_html.'&gt;&lt;label class="sf-label-checkbox" for="'.$input_id.'"&gt;' . $category_name;
  
  
           } else if  ($input_name == "_sft_management_level[]") {
  
              echo '&lt;li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'&gt;&lt;input '.$input_attibutes_html.'&gt;&lt;label class="sf-label-checkbox" for="'.$input_id.'"&gt;' . $category_name;
  
  
  
           } else {
  
              echo '&lt;li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'&gt;&lt;input '.$input_attibutes_html.'&gt;&lt;label class="sf-label-checkbox" for="'.$input_id.'"&gt;' . $category_name . '&lt;/label&gt;&lt;a class="eModal-post-'.$category_id.'" href="'.$category_link.'"&gt;&lt;i class="fa fa-info-circle"&gt;&lt;/i&gt;&lt;/a&gt;';
  
              echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "&lt;div class='col-md-12'&gt;" . $category_desc . "&lt;/div&gt;" . "[/modal]");
  
           }
  
  
           if(isset($option-&gt;depth))
           {//then we do depth calculations
  
              $current_depth = $option-&gt;depth;
  
              $close_li = true;
              $open_child_list = false;
              $close_ul = false;
  
              $next_depth = -1;
  
              if(isset($input_args['options'][$i+1]))
              {
                 $next_option = $input_args['options'][$i+1];
                 $next_depth = $next_option-&gt;depth;
              }
  
              if($next_depth!=-1)
              {
                 if($next_depth!=$current_depth)
                 {//there is a change in depth
  
                    if($next_depth&gt;$current_depth)
                    {//then we need to open a child list
                       //and, not close the current li
                       $open_child_list = true;
                       $close_li = false;
                    }
                    else
                    {
                       $close_ul = true;
                    }
                 }
              }
  
              if($open_child_list)
              {
                 $open_child_count++;
                 echo '&lt;ul class="children"&gt;';
              }
              if($close_li)
              {
                 echo "&lt;/li&gt;";
              }
              if($close_ul)
              {
                 $diff = $current_depth - $next_depth;
                 $open_child_count = $open_child_count - $diff;
                 $str_repeat = str_repeat("&lt;/ul&gt;&lt;/li&gt;", $diff);
                 echo $str_repeat;
              }
           }
        }
  
        $str_repeat = str_repeat("&lt;/ul&gt;&lt;/li&gt;", (int)$open_child_count);
        echo $str_repeat;
  
        ?&gt;
     &lt;/ul&gt;
     &lt;?php
  
     $output = ob_get_clean();
  
     return $output;
  }
  </code></pre>