Warning: This function has been deprecated. Use wp_dropdown_categories() instead.

wp_dropdown_cats() WordPress Function

The wp_dropdown_cats() function displays a dropdown list of categories. The list can be used to select a default category for new posts.

wp_dropdown_cats( int $current_cat, int $current_parent, int $category_parent, int $level, array $categories ) #

Legacy function used for generating a categories drop-down control.


Description

Top ↑

See also


Top ↑

Parameters

$current_cat

(int)(Optional) ID of the current category. Default 0.

$current_parent

(int)(Optional) Current parent category ID. Default 0.

$category_parent

(int)(Optional) Parent ID to retrieve categories for. Default 0.

$level

(int)(Optional) Number of levels deep to display. Default 0.

$categories

(array)(Optional) Categories to include in the control. Default 0.


Top ↑

Return

(void|false) Void on success, false if no categories were found.


Top ↑

Source

File: wp-admin/includes/deprecated.php

function wp_dropdown_cats( $current_cat = 0, $current_parent = 0, $category_parent = 0, $level = 0, $categories = 0 ) {
	_deprecated_function( __FUNCTION__, '3.0.0', 'wp_dropdown_categories()' );
	if (!$categories )
		$categories = get_categories( array('hide_empty' => 0) );

	if ( $categories ) {
		foreach ( $categories as $category ) {
			if ( $current_cat != $category->term_id && $category_parent == $category->parent) {
				$pad = str_repeat( '– ', $level );
				$category->name = esc_html( $category->name );
				echo "\n\t<option value='$category->term_id'";
				if ( $current_parent == $category->term_id )
					echo " selected='selected'";
				echo ">$pad$category->name</option>";
				wp_dropdown_cats( $current_cat, $current_parent, $category->term_id, $level +1, $categories );
			}
		}
	} else {
		return false;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Use wp_dropdown_categories()
1.2.0Introduced.

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.

Show More