List categories with checkbox in Wordpress Options?

11,456

Solution 1

i want to write category id to input value. but it is blank. what i have to do for this problem?

my code :

    $categories = get_categories('orderby=name');  
$wp_cats = array();  
foreach ($categories as $category_list ) 
{  
      $wp_cats[$category_list->cat_ID] = $category_list->cat_name;  
}  

foreach ($wp_cats as $v) {
   echo "<input type='checkbox' name='mychecky' value='$category[cat_ID]' />";
   echo $v;
   echo '<br>';
}

i solved my problem with this code block

$categories=get_categories();   foreach($categories as $category) {     echo "<input type='checkbox' name='mychecky' value='$category->term_id' />";    echo $category->cat_name;
    echo '<br>';    }

Solution 2

You can use wp_terms_checklist function (http://codex.wordpress.org/Function_Reference/wp_terms_checklist)

Share:
11,456
Keith Donegan
Author by

Keith Donegan

Just another Developer...

Updated on June 28, 2022

Comments