Using WordPress ‘dropdown_cats()’ PHP function

The dropdown_cats() WordPress PHP function is a deprecated method that was once used for generating a dropdown of categories.

Usage

Here’s a generic example of how to use the deprecated dropdown_cats() function. Keep in mind that you should use wp_dropdown_categories() instead in modern WordPress development.

dropdown_cats($optionall, $all, $orderby, $order, $show_last_update, $show_count, $hide_empty, $optionnone, $selected, $exclude);

Parameters

  • $optionall (int) (Optional) Default: 1
  • $all (string) (Optional) Default: ‘All’
  • $orderby (string) (Optional) Default: ‘ID’
  • $order (string) (Optional) Default: ‘asc’
  • $show_last_update (int) (Required)
  • $show_count (int) (Required)
  • $hide_empty (int) (Optional) Default: 1
  • $optionnone (bool) (Optional) Default: false
  • $selected (int) (Required)
  • $exclude (int) (Required)

More information

See WordPress Developer Resources: dropdown_cats()

The dropdown_cats() function was deprecated in WordPress 2.1.0. You should use wp_dropdown_categories() instead.

Examples

Example 1

Here, we use dropdown_cats() to generate a dropdown list with an option to show all categories, ordered by ID in ascending order.

dropdown_cats(1, 'All', 'ID', 'asc', 1, 1, 1, false, 2, 0);

Example 2

In this example, we’re generating a dropdown list that hides empty categories, and the ‘none’ option is enabled.

dropdown_cats(1, 'All', 'ID', 'asc', 1, 1, 1, true, 2, 0);

Example 3

This example generates a dropdown list excluding category with ID 3.

dropdown_cats(1, 'All', 'ID', 'asc', 1, 1, 1, false, 2, 3);

Example 4

Here, we’re generating a dropdown list with ‘none’ option enabled, excluding category with ID 3.

dropdown_cats(1, 'All', 'ID', 'asc', 1, 1, 1, true, 2, 3);

Example 5

In this example, we’re generating a dropdown that doesn’t show the ‘All’ option.

dropdown_cats(1, '', 'ID', 'asc', 1, 1, 1, false, 2, 0);

Remember, the dropdown_cats() function is deprecated, and these examples are provided for understanding the old code. You should use the wp_dropdown_categories() function for any new development.