Outputs an unordered list of checkbox input elements labeled with category names.
Description
See also
Parameters
$post_id
intoptional- Post to generate a categories checklist for. Default 0.
$selected_cats must not be an array. Default 0. $descendants_and_self
intoptional- ID of the category to output along with its descendants.
Default 0. $selected_cats
int[]|falseoptional- Array of category IDs to mark as checked.
Default:
false
$popular_cats
int[]|falseoptional- Array of category IDs to receive the "popular-category" class.
Default:
false
$walker
Walkeroptional- Walker object to use to build the output.
Default is a Walker_Category_Checklist instance.Default:
null
$checked_ontop
booloptional- Whether to move checked items out of the hierarchy and to the top of the list.
Default:
true
Source
function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
wp_terms_checklist(
$post_id,
array(
'taxonomy' => 'category',
'descendants_and_self' => $descendants_and_self,
'selected_cats' => $selected_cats,
'popular_cats' => $popular_cats,
'walker' => $walker,
'checked_ontop' => $checked_ontop,
)
);
}
Changelog
Version | Description |
---|---|
2.5.1 | Introduced. |
Basic Example
Outputs a list of all categories:
Output a the list of a certain category and its descendants
Mark all categories for a particular post as checked
Specify an array of categories to preselect instead
To override which categories will be marked as popular
Specify a walker object to use
List the checked categories before the rest
You may also use any of the parameters in combination, except for $post_id and $selected_cats, which should not be used together.