Create a checkbox for tags in WordPress

Im editing a plugin because I want to create a checkbox for the tags the plugin has. In this moment Ive got in a variable, this array:

array(9) { [129]=> object(EM_Tag)#84 (15) { ["id"]=> string(3) "129" ["term_id"]=> string(3) "129" ["name"]=> string(35) "Accessible for non-English speakers" ["slug"]=> string(11) "non-english" ["term_group"]=> string(1) "0" ["term_taxonomy_id"]=> string(3) "129" ["taxonomy"]=> string(10) "event-tags" ["description"]=> string(0) "" ["parent"]=> string(1) "0" ["count"]=> string(1) "0" ["fields"]=> array(0) { } ["required_fields"]=> array(0) { } ["feedback_message"]=> string(0) "" ["errors"]=> array(0) { } ["mime_types"]=> array(3) { [1]=> string(3) "gif" [2]=> string(3) "jpg" [3]=> string(3) "png" } } }

There are more tags but I just put one. I would like to generate a checkbox for each tag.

Related posts

1 comment

  1. One solution is to iterate over the array that you provided and access the fields that way. I made a shortened array with proper indentation based on your example provided. It seems to be the same but let me know otherwise.

    $array = array(
        129 => array(
            'id' => '129',
            'name' => 'Accessible for non-English Speakers'
        ),
        130 => array(
            'id' => '130',
            'name' => 'A second piece of information'
        ),
        131 => array(
            'id' => '131',
            'name' => 'A third piece of information'
        )
    );
    
    // Iterate over the array
    foreach ($array as $c) {
        // Access the required data
        $id = $c['id'];
        $name = $c['name'];
    
        // Generate your checkbox
        print "<input type='checkbox' name='$name' id='$id'>";
    }
    

Comments are closed.