Get Terms as Checkboxes

This makes working with filters so much easier. Many thanks to the original poster.


function get_terms_checkboxes($taxonomies, $args) {
  $terms = get_terms($taxonomies, $args);
  foreach($terms as $term){
    $output .= '<label for="'.$term->slug.'"><input type="checkbox" id="'.$term->slug.'" name="'.$term->taxonomy.'" value="'.$term->slug.'"> '.$term->name.'</label>';
  return $output;

Place within template:

<?php echo get_terms_chekboxes('taxonomy', $args = array('hide_empty'=>true)); ?>

Sourced here.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.

%d bloggers like this: