Languages: English • 日本語 (Add your language)
Output an unordered list of checkbox <input> elements labeled with category names. This is essentially a convenience function for simplifying calls to wp_terms_checklist()
<?php
wp_category_checklist( $post_id, $descendants_and_self, $selected_cats,
$popular_cats, $walker, $checked_ontop);
?>
While strictly speaking all parameters are optional because there are defaults, this function is not so useful without specifying either a $post_id or an array of $selected_cats. But don't try to do both.
Output a list of all categories:
wp_category_checklist();
Output a the list of a certain category and its descendants:
$category_id = 22; wp_category_checklist( 0, $category_id );
Mark all categories for a particular post as checked:
$post_id = 45; wp_category_checklist( $post_id );
Specify an array of categories to preselect instead:
$selected_cats = array( 45, 33, 118 ); wp_category_checklist( 0, 0, $selected_cats );
To override which categories will be marked as popular:
$popular = array( 45, 33, 118 ); wp_category_checklist( 0, 0, false, $popular );
Specify a walker object to use:
$walker = new My_Walker_Category_Checklist; wp_category_checklist( 0, 0, false, false, $walker );
List the checked categories before the rest:
$selected_cats = array( 45, 33, 118 ); $checked_ontop = true; wp_category_checklist( 0, 0, $selected_cats, false, null, $checked_ontop );
You may also use any of the parameters in combination, except for $post_id and $selected_cats, which should not be used together.
Since 2.5.1
wp_category_checklist() is located in wp-admin/includes/template.php
.