WordPress media manager multiple selection output

I’m trying to use media manager in metabox, and I need to use multiple select.
I just have problem with doing output from that selection. I need element in metabox to hold all selected files urls.
My code is here:

jQuery(document).ready(function($){
var custom_uploader;
$('#upload_image_button').click(function(e) {
    e.preventDefault();
    //If the uploader object has already been created, reopen the dialog
    if (custom_uploader) {
        custom_uploader.open();
        return;
    }
    //Extend the wp.media object
    custom_uploader = wp.media.frames.file_frame = wp.media({
        title: 'Choose Image',
        button: {
            text: 'Choose Image'
        },
        multiple: true
    });
    custom_uploader.on('select', function() {
        selection.map( function( attachment ) {
        attachment = attachment.toJSON();
        $("#obal").after("<img src=" +attachment.url+">");
        });
    });
    custom_uploader.open();
});
});

What’s wrong with it?

Related posts

1 comment

  1. It was just my mistake… I’ve forgotten improve var selection

    jQuery(document).ready(function($){
      var custom_uploader;
      $('#upload_image_button').click(function(e) {
        e.preventDefault();
        //If the uploader object has already been created, reopen the dialog
        if (custom_uploader) {
          custom_uploader.open();
          return;
        }
        //Extend the wp.media object
        custom_uploader = wp.media.frames.file_frame = wp.media({
          title: 'Choose Image',
          button: {
            text: 'Choose Image'
          },
          multiple: true
        });
        custom_uploader.on('select', function() {
          var selection = custom_uploader.state().get('selection');
          selection.map( function( attachment ) {
            attachment = attachment.toJSON();
            $("#obal").after("<img src=" +attachment.url+">");
          });
        });
        custom_uploader.open();
      });
    });
    

Comments are closed.