Reputation: 2063
In the WordPress 3.5 media manager under the "Create Gallery" tab, users can choose multiple images and then have the ability to reorder images in a second page. When done, it inserts a shortcode such as: [gallery ids="895,1007,986"]
I would like to use this same interface so that users can select and reorder images. However, instead of returning a shortcode, I would like to return just a list of ID's of the images like so: 895,1007,986
Another important thing is that my button will be in a metabox and the list of ID's will not be placed inside TinyMCE post edit area.
How can I achieve this?
Thank You.
Upvotes: 4
Views: 2150
Reputation: 9496
You can call a = wp.media.gallery.edit('[gallery ids="2,1,3..."]');
like Wordpress does in media-editor.js.
I wasn't sure what event can catch the update, I found it with a.on('all',function(n,a) {console.log(n); console.log(a)})
Notice "update" in the log, and an object with a models
array with the images. So, the quickest solutions using the gallery selector would be:
wp.media.gallery.edit('[gallery ids="numberlist"]').on('update',function(obj)
{ do something with obj.models)})
Upvotes: 5