Created
          July 12, 2021 13:14 
        
      - 
      
- 
        Save annelyse/2d4a469be80d966b4ca896bdefee7e7d to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| function terms_list($taxonomy, $orderby, $order, $empty = true, $type = "radio") | |
| { | |
| $term_args = array( | |
| 'orderby' => $orderby, | |
| 'order' => $order, | |
| 'hide_empty' => $empty, | |
| ); | |
| $terms = get_terms($taxonomy, $term_args); | |
| // var_dump( get_taxonomy($taxonomy)); | |
| $label = get_taxonomy($taxonomy); | |
| if( is_tax('tax_category')){ | |
| $queryObject= get_queried_object(); | |
| $queryObjectID = $queryObject->term_id; | |
| } | |
| if ($type == 'radio') { | |
| if ($terms) { | |
| foreach ($terms as $term) { | |
| $color = get_field('cat_color', 'term_' . $term->term_id); | |
| $style = ""; | |
| if (!empty($color)) { | |
| $style = 'style="color:' . $color . ';"'; | |
| }; | |
| $checked=''; | |
| if( !empty( $queryObjectID ) && $queryObjectID == $term->term_id ){ | |
| $checked = 'checked'; | |
| } | |
| echo '<div class="form-group" ' . $style . '>'; | |
| echo '<input type="radio" '.$checked.' name="'. $taxonomy.'" value="' . $term->term_id . '" id="filter-' . $term->slug . '">'; | |
| echo '<label for="filter-' . $term->slug . '"><span>' . $term->name . '</span></label>'; | |
| echo '</div>'; | |
| } | |
| } | |
| } | |
| if ($type == 'select') { ?> | |
| <select name="<?= $taxonomy; ?>" id="<?= $taxonomy; ?>"> | |
| <option value=""><?= $label->label; ?></label> | |
| <?php | |
| if ($terms) { | |
| foreach ($terms as $term) { | |
| $color = get_field('cat_color', 'term_' . $term->term_id); | |
| $style = ""; | |
| if (!empty($color)) { | |
| $style = 'style="color:' . $color . ';"'; | |
| }; | |
| echo '<option ' . $style . ' value=' . $term->term_id . '"><span>' . $term->name . '</span></label>'; | |
| } | |
| } | |
| ?> | |
| </select> | |
| <?php | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment