wp_dropdown_cats

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

Description

(bool|null) wp_dropdown_cats( (int) $currentcat = 0, (int) $currentparent = 0, (int) $parent = 0, (int) $level = 0, (int) $categories = 0 ); 

Returns (bool|null)

False if no categories were found.

Parameters (5)

0. $currentcat — Optional. (int)
ID of the current category. Default 0.
1. $currentparent — Optional. (int)
Current parent category ID. Default 0.
2. $parent — Optional. (int)
Parent ID to retrieve categories for. Default 0.
3. $level — Optional. (int)
Number of levels deep to display. Default 0.
4. $categories — Optional. (int)
Categories to include in the control. Default 0.

Usage

  1. if ( !function_exists( 'wp_dropdown_cats' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/deprecated.php'; 
  3.  
  4. // Optional. ID of the current category. Default 0. 
  5. $currentcat = -1; 
  6.  
  7. // Optional. Current parent category ID. Default 0. 
  8. $currentparent = -1; 
  9.  
  10. // Optional. Parent ID to retrieve categories for. Default 0. 
  11. $parent = -1; 
  12.  
  13. // Optional. Number of levels deep to display. Default 0. 
  14. $level = -1; 
  15.  
  16. // Optional. Categories to include in the control. Default 0. 
  17. $categories = -1; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = wp_dropdown_cats($currentcat, $currentparent, $parent, $level, $categories); 
  21.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/deprecated.php  
  1. function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) { 
  2. _deprecated_function( __FUNCTION__, '3.0.0', 'wp_dropdown_categories()' ); 
  3. if (!$categories ) 
  4. $categories = get_categories( array('hide_empty' => 0) ); 
  5.  
  6. if ( $categories ) { 
  7. foreach ( $categories as $category ) { 
  8. if ( $currentcat != $category->term_id && $parent == $category->parent) { 
  9. $pad = str_repeat( '– ', $level ); 
  10. $category->name = esc_html( $category->name ); 
  11. echo "\n\t<option value='$category->term_id'"; 
  12. if ( $currentparent == $category->term_id ) 
  13. echo " selected='selected'"; 
  14. echo ">$pad$category->name</option>"; 
  15. wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories ); 
  16. } else { 
  17. return false;