Make WordPress Core

Opened 9 years ago

Closed 5 years ago

#16734 closed enhancement (wontfix)

Allowing multiple selection when using wp_dropdown_* functions

Reported by: grandslambert Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords: needs-patch
Focuses: Cc:

Description (last modified by wonderboymusic)

I would like to be able to pass an argument to wp_dropdown_categories() to allow the user to select more than one category using a CTRL-CLICK. I can use a preg_replace to add the multiple tag to the html select tag, but I cannot pass multiple selections in the "selected" argument.

Attachments (4)

category-template.php.diff (1.6 KB) - added by grandslambert 9 years ago.
Change in the category-template.php to support multipe select boxes.
wp-admin.css.diff (115.1 KB) - added by grandslambert 9 years ago.
Change in the wp-admin.css to add a class to make the multiple select taller.
16734.diff (2.9 KB) - added by wonderboymusic 6 years ago.
16734.2.diff (4.0 KB) - added by DrewAPicture 6 years ago.

Download all attachments as: .zip

Change History (23)

9 years ago

Change in the category-template.php to support multipe select boxes.

9 years ago

Change in the wp-admin.css to add a class to make the multiple select taller.

#1 @greuben
9 years ago

I don't know how useful this feature will be but for css and javascript files you need to submit a patch using their respective .dev files.

#2 @grandslambert
9 years ago

I am working on some plugins and want people to be able to select multiple categories. I tried to use the checkboxes like on the post page but there does not seem to be a really useful method for creating those that I can find. I played around with wp_terms_checklist() but could not get it to accept my selected categories - it just checked whatever it felt like checking. I need to use this in a widget form.

#3 @prionkor
9 years ago

@grandslambert: Ability to have multiple selection should be added. I am absolutely with you!

The feature can be something like adding an extra argument array which we can call attribute array. This way we can add id, classes, multiple or any other attribute on the select field.

Last edited 9 years ago by prionkor (previous) (diff)

#4 @prionkor
9 years ago

  • Keywords dev-feedback added
  • Version changed from 3.1 to 3.3

#5 @SergeyBiryukov
9 years ago

  • Version changed from 3.3 to 3.1

Version field indicates when the enhancement was initially suggested.

#6 @Gecka
9 years ago

Dear Wordpress Core "Devs",

You really know how to discourage developers to contribute to wordpress. Well done. I found so many little fixes or small nifty additions that never got their way into core or have been rewritten by you, letting behind the original author credit.

The world should know about that!


BTW WP is a great product, I really hope that one day some will fork that project over github and will allow contributing!

#7 @mbijon
9 years ago

(troll-bait taken, admins feel free to delete this comment that has nothing to do with the ticket)

@Gecka, I think the extra discussion that happens here on Trac is vital to keeping WordPress stable and promulgating best practices. Whether core is in SVN or Git it's the discussions here that often refine, change or keep code out of core. And, while there are tools that might be able to parallel what happens on Trac, those are GitHub-specific and not general Git tools.

Besides the core team is working to reduce the hurdles to contributing:

#8 @nacin
7 years ago

  • Component changed from General to Taxonomy

#9 @wonderboymusic
6 years ago

#24731 was marked as a duplicate.

6 years ago

#10 @wonderboymusic
6 years ago

  • Description modified (diff)
  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 4.0
  • Summary changed from Allowing multiple selection when using wp_dropdown_categories to Allowing multiple selection when using wp_dropdown_* functions

16734.diff adds 'multiple' => false to the default args for wp_dropdown_(categories|pages|users)().

No instances in core use this, but it will allow users to have multiple-select for whatever their little hearts desire.

#11 @DrewAPicture
6 years ago

  • Keywords needs-docs added

#12 @prionkor
6 years ago

I am glad, after 3 years. Looks like this change is going to make it to the core! :)

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.

6 years ago

#14 @helen
6 years ago

  • Keywords needs-patch added; has-patch removed

I like this, despite it making the function name of "dropdown" a little fuzzy. Needs a patch that accounts for an array of values for selected(), though. And in the next couple days, or we'll have to punt once we hit beta.

#15 @prionkor
6 years ago

I was wondering if a array of key values pair could be passed which later becomes attribute value pair. We could introduce a new attribute key.

For example

$args = array(
        'orderby'            => 'ID', 
	'order'              => 'ASC',
	'show_count'         => 0,
	'hide_empty'         => 1, 
	'child_of'           => 0,
	'exclude'            => '',
	'echo'               => 1,
	'selected'           => 0,
	'hierarchical'       => 0, 
        'attributes' => array(
                              'multiple' => 'multiple',
                              'data-name' => 'datavalue1'
                              'data-name2' => 'datavalue2'


This would be helpful if we want to pass custom attributes like data-.

6 years ago


#16 @DrewAPicture
6 years ago

  • Keywords needs-docs removed

16734.2.diff adds docs. Still doesn't account for an array of values in selected() as requested in comment:14.

#17 @nacin
6 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from 4.0 to Future Release

As already stated, because <select multiple> have issues with <option selected> at least in terms of this API, I think we need to avoid touching this for the moment, until we have that resolved. Ultimately, this hasn't had enough forethought put into it for it to squeeze into 4.0 on the eve of beta.

Modifying selected() to handle an array possibly has compatibility issues (though it's possible it's fine). We might need to handle it some other way. selected( in_array( $option, $selected ) ) is fine, as long as $selected is forced to be an array when not multiple.

Bigger question unresolved: <select multiple> is a terrible experience; why would anyone want to inflict that on their users? Since this ticket has been released, browsers have added improved support for various new HTML5 inputs, notably not multiple selects, while new multi-selection libraries have come out like Chosen and Select2. I hesitate allowing WordPress APIs to hackily support something that is well known to be a poor user experience.

#18 @chriscct7
5 years ago

  • Keywords close added; 2nd-opinion removed

Echoing nacin's sentiment, I think that the Select2 multiselect provides a much better UX experience, and once it clears the a11y issues blocking it to core it would provide a significantly superior option than the one currently being proposed on this ticket.

#19 @DrewAPicture
5 years ago

  • Keywords close removed
  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

See comment:17.

Note: See TracTickets for help on using tickets.