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 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.8.1 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | Cc: |
Description
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
<select> <option class="level-0" value="16">Comedy</option> <option class="level-0" value="17">Sci-Fi</option> </select>
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:
<?php <?php /* 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' ); wp_list_categories($args); ?>
and in wp_list_categories
we add this before the $html gets returned from the function.
<?php $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)
Note: See
TracTickets for help on using
tickets.