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)
Comments
-
Keith Donegan almost 2 years
How would I go about displaying all of a site’s categories in checkboxes in my options panel?
I can get a dropdown select menu to work, I just have no idea how to implement checkboxes.
Code Here from Net Tuts: http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/
Thanks in advance.