I'm a beginner in jQuery, Multiple image upload Button implement with WordPress Media Uploader is not working, I need to know how to do the right way.
Here's my code: Javascript/jQuery For displaying the media uploader and handling the selected images:
jQuery(document).ready( function($){
var mediaUploader;
$('#upload-button').on('click',function(e) {
e.preventDefault();
if( mediaUploader ){
mediaUploader.open();
return;
}
mediaUploader = wp.media.frames.file_frame =wp.media({
title: 'Choose a Hotel Picture',
button: {
text: 'Choose Picture'
},
multiple:false
});
mediaUploader.on('select', function(){
attachment = mediaUploader.state().get('selection').first().toJSON();
$('#profile-picture').val(attachment.url);
$('#profile-picture-preview').css('background-image','url(' + attachment.url + ')');
});
mediaUploader.open();
}); });
<input type="button" id="upload-button1" class="button button-secondary" value="Upload Profiel Picture">
<input type="hidden" name="profile_picture1" id="profile-picture1" value="'.$picture.'">
<input type="button" id="upload-button2" class="button button-secondary" value="Upload Profiel Picture">
<input type="hidden" name="profile_picture2" id="profile-picture2" value="'.$picture.'">
Any help, as always, is greatly appreciated.