get_categories include/exclude arguments
-
Hello,
at the moment i am using the code below wo receive a list of all of my categories.
In my case i want to add a checkbox before every category except the parent categories, these should be blank.Now i have an array which contains ids of categories which should be able to display, all other categories shouldn’t be displayed/in the output.
f.e.$allowed = array(15,24,44,90);I read about the inlude/exclude arguements but wasnt able to find clear description how they work. Are they a solution for my needs? Or can i work with the get_categories filter reference?
Thank you very much in advance!
<ul style="list-style-type: none;"> <?php // get parent categories $parent_cats = get_categories( array( 'orderby' => 'name', 'parent' => 0, 'hide_empty'=> false )); foreach ( $parent_cats as $pcat ) { // get child categories $child_cats = get_categories( array( 'orderby' => 'name', 'parent' => $pcat->term_id, 'hide_empty'=> false ) ); // if childs, output parent without and childs with checkbox if ($child_cats) { ?> <li> <label> <?php echo $pcat->name; ?> </label> <ul style="list-style-type: none;"> <?php foreach ( $child_cats as $ccat ) { if ($ccat) { ?> <li> <label> <input type="checkbox" class="choose-category" <?php if($this->ztgm_abo_cats[0] != '' AND in_array($ccat->term_id,$this->ztgm_abo_cats[0])) { echo 'checked'; } ?> name="categories[]" value="<?php echo $ccat->term_id; ?>"> <?php echo $ccat->name; ?> ( <?php echo $ccat->term_id;?> ) </label> </li> <?php } } ?> </ul> </li> <?php } // output parent with checkbox else { ?> <li> <label> <input type="checkbox" class="choose-category" <?php if($this->ztgm_abo_cats[0] != '' AND in_array($pcat->term_id,$this->ztgm_abo_cats[0])) { echo 'checked'; } ?> name="categories[]" value="<?php echo $pcat->term_id; ?>"> <?php echo $pcat->name; ?> ( <?php echo $pcat->term_id;?> ) </label> </li> <?php } } ?> </ul>
The topic ‘get_categories include/exclude arguments’ is closed to new replies.