• Heres a simple way to get parent categories only into a list of checkbox values with the category ID as the value. Just use <?php cat_list(); ?> where you want the list to appear.

    function cat_list(){
    		$categoryargs = array(
    		'hide_empty' => false,
    		'walker' => 'object',
    		'depth' => 1
    		);
    		$categories=get_categories($categoryargs);
    		foreach($categories as $category) {
    			if ($category->category_parent == 0){
    				echo "<input type='checkbox' name='mychecky' value='$category->term_id' />";    echo $category->cat_name;echo '<br>';
    			}
    		}
    	}
  • The topic ‘Get Parent Categories as Checkbox Inputs’ is closed to new replies.