Using WordPress ‘dropdown_categories()’ PHP function

The dropdown_categories() WordPress PHP function is a legacy function primarily used to generate the categories checklist control.

Usage

The function can be used as shown below:

dropdown_categories($default_category, $category_parent, $popular_ids = array());

Custom Example:

dropdown_categories(1, 0, array(2, 3, 4));

In this example, the function generates a dropdown list of categories, with ‘1’ as the default category, ‘0’ as the parent category, and ‘2, 3, 4’ as popular categories.

Parameters

  • $default_category (int) – This required parameter is currently unused.
  • $category_parent (int) – This required parameter is also unused.
  • $popular_ids (array) – This is an optional parameter. It’s unused and defaults to an empty array.

More information

See WordPress Developer Resources: dropdown_categories()

This function is legacy and might be deprecated in future releases. It’s recommended to use wp_category_checklist() instead.

Examples

Basic Usage

This code generates a dropdown with all categories.

dropdown_categories(0, 0);

Default Category

In this case, ‘3’ is set as the default category.

dropdown_categories(3, 0);

Default and Parent Category

Here ‘4’ is the default category and ‘2’ is the parent category.

dropdown_categories(4, 2);

This code includes ‘5, 6, 7’ as popular categories.

dropdown_categories(0, 0, array(5, 6, 7));

All Parameters

In this case, ‘1’ is the default category, ‘0’ is the parent category, and ‘2, 3, 4’ are popular categories.

dropdown_categories(1, 0, array(2, 3, 4));

Remember, the parameters are currently unused and may not impact the output. These examples are meant to demonstrate the syntax and possible usage.