Multiple select support for wp_dropdown_categories
Description
Adds a new argument to the $args array for wp_dropdown_categories, allowing to pass either empty string or multiple.
If left empty, the select defaults to a single select, if multiple is passed the Select will allow for multiple selection and pass an [] to the name attribute value as well.
See also https://forums.classicpress.net/t/update-wp-dropdown-categories-to-allow-for-multiple-selection/
Motivation and context
The requirement to produce a Categories or else Custom taxonomy Dropdown with multiselect support has been around for years (google search will show what I mean). I use to replace said function in my plugins with this (and other) amendments and thus I think it is time to have this tiny, but powerful change in core.
How has this been tested?
This was tested on several installs of mine (I use to replace said function with a custom one). Also tested this particular commit on my local install
Example usage:
wp_dropdown_categories( array('multiple' => 'multiple') );
Screenshots
Before
After
NOTE: This now also allows for Select2 MultiSelects, of course (the developer just needs to instantiate S2 on the select input produced...)
Types of changes
- New Feature (backwards compatible and non-disturbing)
This pull request has been mentioned on ClassicPress Forums. There might be relevant details there:
https://forums.classicpress.net/t/update-wp-dropdown-categories-to-allow-for-multiple-selection/3555/5
This pull request has been mentioned on ClassicPress Forums. There might be relevant details there:
https://forums.classicpress.net/t/update-wp-dropdown-categories-to-allow-for-multiple-selection/3555/6
Needs testing (including automated tests) and revision (changing multiple to a boolean value) similar to #791 .
Pushed 2 commits that:
- Fix poorly styled
@sinceversion (remove CP- prefix, but did NOT update version!) - Transform new argument to boolean
- Add validation for new (and existing) boolean arguments
- Update logic to print
multipleor nothing depending on new argument value passed towp_dropdown_categories
Tested locally for functionality as well.
This shouldn't be closed.
I suspect this auto closed due to fork where PR originated being deleted.
Ah, ups - I guess that would have been me then when I cleaned up old CP repos lying around in my repo.
But I've seen other such things getting "reopened", so I guess this can be done here too?
Unfortunately, the branch is closed. Needs re-opening.
As per latest decisions it seems CP will be re-forked, re-synced with WP, so I think the changes of this PR (and all others I committed in the past improving similar functions) can/should be discarded, since they add new features not in WP and thus would just complicate the keeping-in-sync process.