我正在尝试在自定义meta框中使用wordpress媒体上载器上载多个pdf。但是我只能实现单个pdf上载。如果我要选择两个文件,我想在postmeta中用逗号分隔将两个文件的url保存在单行表。我该如何实现?
Here is my code(Js File):
(function($) {
$(document).ready(function () {
var frame;
$('#add_pdf').on( 'click', function( event ){
event.preventDefault();
if ( frame ) {
frame.open();
return;
}
frame = wp.media({
title: 'Add Product Pdf',
button: {
text: 'Select File'
},
multiple: true
});
frame.on( 'select', function() {
var attachments = frame.state().get('selection').toJSON();
var fileurls = "";
for (let elem in attachments) {
fileurls += attachments[elem].url+',';
}
});
frame.open();
});
$('#remove_pdf').on( 'click', function( event ){
event.preventDefault();
$('.pdf_div').html( '' );
$('.media_input_name').val('');
});
});
})(jQuery);