[wp-trac] [WordPress Trac] #33452: wp_dropdown_categories doesn't respect show_option_all

WordPress Trac noreply at wordpress.org
Thu Aug 20 18:37:21 UTC 2015

#33452: wp_dropdown_categories doesn't respect show_option_all
 Reporter:  dfellini                 |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  4.3.1
Component:  Taxonomy                 |     Version:  4.3
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
Changes (by boonebgorges):

 * keywords:   => has-patch needs-testing
 * milestone:  Awaiting Review => 4.3.1


 Hi dfellini - Welcome to Trac, and thanks for the report!

 I've confirmed the issue. It dates from [32484]. This odd bug arises due
 to an unfortunate combination of (a) the way that the 'selected' argument
 works, and (b) the way PHP interprets `==` between an integer and a

 More specifically: The default 'selected' value in
 `wp_dropdown_categories()` is `0`. In
 `Walker_CategoryDropdown::start_el()`, we do a comparison `if (
 $category->{$value_field} == $args['selected'] )`. Because you're using
 `slug` as your `'value_field'`, the check looks something like this: `if (
 'connecticut' == 0 )`. The problem is that PHP resolves `'connecticut' ==
 0` to `true`; see http://stackoverflow.com/questions/6843030/why-does-php-
 consider-0-to-be-equal-to-a-string for some explanation. So each
 `<option>` in your dropdown is getting `selected="selected"`.

 The most straightforward fix is to cast everything to a string, and to do
 a strict comparison. See [attachment:33452.diff]. Can you have a look to
 see whether this solves your problem?

 This is going to be a relatively large annoyance for people who are
 relying on the default value of 'selected' in `wp_dropdown_categories()`,
 so I'm moving the ticket to 4.3.1 to address in the next minor release.

Ticket URL: <https://core.trac.wordpress.org/ticket/33452#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list