[wp-trac] [WordPress Trac] #41882: Walker_CategoryDropdown does not wrap options inside HTML select element with wp_list_categories
WordPress Trac
noreply at wordpress.org
Thu Sep 14 14:57:51 UTC 2017
#41882: Walker_CategoryDropdown does not wrap options inside HTML select element
with wp_list_categories
------------------------------+-----------------------------
Reporter: subrataemfluence | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.8.1
Severity: normal | Keywords:
Focuses: |
------------------------------+-----------------------------
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
<?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
<?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;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41882>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list