wp_category_checklist() WordPress Function

The wp_category_checklist() function is a Wordpress function that outputs a list of categories as a checklist. The function can be used to display a list of categories for a post, or to select a default category for a new post.

wp_category_checklist( int $post_id, int $descendants_and_self, int[]|false $selected_cats = false, int[]|false $popular_cats = false, Walker $walker = null, bool $checked_ontop = true ) #

Outputs an unordered list of checkbox input elements labeled with category names.


Description

Top ↑

See also


Top ↑

Parameters

$post_id

(int)(Optional) Post to generate a categories checklist for. Default 0. $selected_cats must not be an array. Default 0.

$descendants_and_self

(int)(Optional) ID of the category to output along with its descendants. Default 0.

$selected_cats

(int[]|false)(Optional) Array of category IDs to mark as checked.

Default value: false

$popular_cats

(int[]|false)(Optional) Array of category IDs to receive the "popular-category" class.

Default value: false

$walker

(Walker)(Optional) Walker object to use to build the output. Default is a Walker_Category_Checklist instance.

Default value: null

$checked_ontop

(bool)(Optional) Whether to move checked items out of the hierarchy and to the top of the list.

Default value: true


Top ↑

Source

File: wp-admin/includes/template.php

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,
		)
	);
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.