我试图选择多个图像,然后将ID(逗号分隔)插入文本字段。
这是我的代码,但它只选择第一个图像ID:
jQuery(document).ready(function($){
var custom_uploader;
$(\'#media-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 ) {
$("#media-input").val(attachment.id);
});
});
custom_uploader.open();
});
});
应更改的零件是以
custom_uploader.on(\'select\'