WordPress 3.5 Media Uploader Multiple File Select
You just need to change multiple:true
to multiple:'add'
. This is how default Create Gallery works.
Update
I think media uploader has been updated since question asked and answered. I guess in previous version of wordpress multiple: 'add'
option was not present as suggested by other users. I'm not sure enough.
Everything's good with your code. Just a small part missing.
selection.map( function( attachment ) {
attachment = attachment.toJSON();
$("#something").after("<img src=" +attachment.url+">");
});
After attachment
converted toJSON
you can use it as mentioned in documentation. You can place image urls into some hidden fields posting to server and display selected images to user same time.
Just a small thing I feel weird is that, we need to press ctrl+click to select images. It should be rather checkboxes or something.
update
ctrl+click or shift+click for selecting multiple images is the way wordpress have given. For a closer look, open
...\wp-includes\js\media-views.js
There's a function defined - toggleSelectionHandler
. It listens for key combination user has pressed and accordingly calls other function which changes certain classes and cause actual selection.
After inspecting into firbug, you can see two classes are applied --
selected
details
details
class defines styles for current clicked/active selection ( with blue thick border) and selected
actually marks image as selected and returns it in selection array.
You can alter that behaviour either from that file itself or write your own function to handle selection. First approach is not good though.
PS : Wordpress does not actually use above file. It chooses compressed version of same file. So you might want to load uncompressed file and play around. You can force wordpress to use uncompressed js files by setting
define('SCRIPT_DEBUG', true);
in wp-config.php
. This will skip behaviour of load-scripts.php
(loading compressed
version of every js file into single file by merging them ).
In case anyone wants to know how to do this, one way is this. Note that it will completely override the default behavior within the scope it is implemented.
wp.media.view.Attachment.prototype.toggleSelectionHandler = function( event ) {
var method = 'between';
if ( event.shiftKey ) {
method = 'between';
} else {
method = 'toggle';
}
this.toggleSelection({
method: method
});
};
If multiple
is set to true
then this will allow you to select multiple items, like in the gallery screen.