Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#41882 new defect (bug)

Walker_CategoryDropdown does not wrap options inside HTML select element with wp_list_categories

Reported by: subrataemfluence's profile subrataemfluence Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8.1
Component: Taxonomy Keywords: has-patch
Focuses: Cc:


If I use Walker_CategoryDropdown() class to build a dropdown list with wp_list_categories function, the output does not get wrapped inside <select>...</select> element. The rendered output is like this:

<option class="level-0" value="16">Comedy</option>
<option class="level-0" value="17">Sci-Fi</option>

when it should be like

   <option class="level-0" value="16">Comedy</option>
   <option class="level-0" value="17">Sci-Fi</option>

In order to achieve this we can add an additional parameter html_wrapper_element in wp_list_categories function and pass a value dorpdown in the argument like:

/* Template Name: Movie List */
require_once ABSPATH . 'wp-admin/includes/template.php';
$args = array(
    'taxonomy' => 'movies_taxonomy',
    'walker' => new Walker_CategoryDropdown(),
    'hide_empty' => false,
    'html_wrapper_element' => 'dropdown'


and in wp_list_categories we add this before the $html gets returned from the function.

$html = apply_filters( 'wp_list_categories', $output, $args );
if( isset($r['html_wrapper_element'])  && $r['html_wrapper_element'] === 'dropdown') {
  $html = '<select>' . $html . '</select>';

if ( $r['echo'] ) {
  echo $html;
} else {
  return $html;

Attachments (1)

41882.diff (683 bytes) - added by subrataemfluence 7 years ago.

Download all attachments as: .zip

Change History (2)

#1 @subrataemfluence
7 years ago

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.