I want to have a media frame that pops up on click of a button on an existing media frame. This way I can associate another attachment with that attachment.
This question shows an example of you can have two media frames for two reasons.
How to create different media uploader frames / filter library depending on a custom action
I want to have a media frame that pops up on click of a button on an existing media frame. This way I can associate another attachment with that attachment.
This question shows an example of you can have two media frames for two reasons.
How to create different media uploader frames / filter library depending on a custom action
I figured this out. You CAN open another frame Here is my code:
jQuery(document).ready(function ($) {
var frame;
frame = wp.media();
$(document).on('click', '.compat-field-add_attachment input', function (e) {
get_attachment(frame);
});
});
function get_attachment(frame) {
// Create the media frame.
frame = wp.media.frames.meta_image_frame = wp.media({
// Tell the modal to show only images.
library: {
type: 'image'
},
});
// When an image is selected, run a callback.
frame.on('close', function () { // Grab the selected attachment.
attachment = frame.state().get('selection').first().toJSON();
attachment_url = attachment.url;
$('.compat-field-add_attachment input').val(attachment_url);
});
frame.open();
}