plugins - Can you open a media frame to sellect an attachment to associate with another attachment you are editing on an existin

admin2025-01-08  15

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

Share Improve this question edited Nov 28, 2024 at 18:14 Enjabain asked Nov 27, 2024 at 11:27 EnjabainEnjabain 1013 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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();


}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265804a1071.html

最新回复(0)