How to make checkboxes from taxonomy terms?

I can populate selectbox options like this:

    <?php 
        $args = array(
            'taxonomy' => array(
                'country',
            ),
            'hide_empty' => 0,
            'name' => 'country'
        );
    ?>
    <?php wp_dropdown_categories($args); ?>

But the problem is how to make a checkbox list instead of a dropdown?

Read More

I mean something like this:

enter image description here

Related posts

1 comment

  1. $taxonomy     = 'training_cats';
     $orderby      = 'name'; 
     $show_count   = 0;      // 1 for yes, 0 for no
     $pad_counts   = 0;      // 1 for yes, 0 for no
     $hierarchical = 0;      // 1 for yes, 0 for no
     $title        = '';
     $empty        = 0;
     $args = array(
      'name'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title,
      'hide_empty'   => $empty
    );
    $cats = get_taxonomies($args);
    foreach ( $cats as $cats2 ) {
     echo '<input type="checkbox" name="checkbox_id" value="'.$cats2->name.'" />';
     echo $cats2-name;
    }
    

    Not tested but should work, change the taxonomy name etc 🙂

    Edit: Try the new code, using get_taxonomies (the code didn’t know where to pull data from)

    Edit2: Changed taxonomy to name:

Comments are closed.