Skip to content

Instantly share code, notes, and snippets.

@lunaroja
Last active November 25, 2018 19:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunaroja/5843383 to your computer and use it in GitHub Desktop.
Save lunaroja/5843383 to your computer and use it in GitHub Desktop.
Wordpress: Get taxonomy terms as checkboxes with labels
<?php
function get_terms_chekboxes($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;
}
echo get_terms_chekboxes('country', $args = array('hide_empty'=>true));
@Warface
Copy link

Warface commented Mar 26, 2014

Awesome script simple and working as it should

@awunsch
Copy link

awunsch commented Jul 12, 2017

Hi, thanks for the great script :) How can you save the selected categories?

Best regards
André

@maugelves
Copy link

Thanks for the script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment