mardi 28 juillet 2015

Comparing two arrays and print checkboxes depending on whats found

I am trying to compare category id's in wordpress with another array. Here is what i have but it doesnt seem to work. If the id exists in the array i want to print a checkbox for that id.

<?php 

  $terms = get_terms('user_category');
  $d = array(1,2,3);

   foreach ( $terms as $term ) {
     if (in_array($term->term_id, $d)) {
        echo '<input type="checkbox" name="category[]" value="'.$term->term_id.'">' . $term->name . '<br>';
    }else{
       echo '';   
    }
  }
?>

I know that the term id's are contained in the array so it must be the if statement that is wrong, any ideas?

Aucun commentaire:

Enregistrer un commentaire