Skip to content

Instantly share code, notes, and snippets.

Created November 8, 2010 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/667683 to your computer and use it in GitHub Desktop.
Save anonymous/667683 to your computer and use it in GitHub Desktop.
Code to create an checkbox of WP Taxonomy in Metabox Class
function checkbox_state($term_id, $terms)
{
foreach ($terms as $term):
if ($term_id == $term->term_id)
echo 'checked';
endforeach;
}
function checkbox_taxonomy($taxonomy_name, $mb)
{
$args = array('name'=>$taxonomy_name);
$taxonomy = array_pop(get_taxonomies( $args, 'objects'));
?>
<div id=five_columns class=checkbox_container>
<label class="checkbox-title"><?php echo $taxonomy->labels->name; ?><!--<span>(optional)</span>--></label>
<div class="panel">
<?php
$terms = get_terms($taxonomy->name, 'orderby=name&hide_empty=0');
$post_terms = wp_get_post_terms( $mb->current_post_id, $taxonomy->name);
$mb->the_field($taxonomy->name);
?>
<ul class="list:effect categorychecklist form-no-clear" id="effectchecklist">
<?php foreach ($terms as $term): ?>
<li class="popular-category" id="<?php echo $taxonomy->name;?>">
<label class="checkbox-label">
<input type="checkbox" name="<?php $mb->the_name(); ?>[]" value="<?php echo $term->term_id; ?>"<?php checkbox_state($term->term_id, $post_terms); ?>>
<?php echo $term->name; ?>
</label>
</li>
<?php endforeach; ?>
</ul>
<!--<select name="<?php $mb->the_name(); ?>">
<?php foreach ($terms as $term): ?>
<option value="<?php echo $term->term_id; ?>"<?php $mb->the_select_state($term->term_id); ?>
<?php echo '>' . $term->name; ?>
</option>
<?php endforeach; ?>
</select>-->
</div>
<!--<span>Selecteer <?php echo $taxonomy->labels->name; ?></span>-->
<input class="add" type="text" name="312" value=""/>
<a href="#" class="button" style="" onclick="321">Add</a>
</div>
<?php
}
?>
<!-- usage -->
<?php
checkbox_taxonomy('problem', $mb);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment