4

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.

NoBugs
  • 9,310
  • 13
  • 80
  • 146
ambiguousmouse
  • 1,983
  • 3
  • 22
  • 27

1 Answers1

5

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)})
NoBugs
  • 9,310
  • 13
  • 80
  • 146
  • 2
    Awesome! Here is the code I used to get the numberlist: `a = wp.media.gallery.edit('[gallery ids="2,1,3..."]').on('update', function(obj) { var numberlist = []; $.each(obj.models, function(id,val) {numberlist.push(val.id)}); do something with numberlist.join(",") });` – ambiguousmouse Jan 13 '13 at 00:24