1

I am trying to add a unique custom tab to the Media Uploader using this code.

var customMedia = wp.media({
    state: 'customState',
    states: [
        new wp.media.controller.Library({
            id: 'customState', 
            title: 'Library',
            library: wp.media.query({
                type: 'image',
                category: 'icon' // adding a filter to ajax_query_attachments_args
            }),
            multiple: false,
            date: false,
        })
    ]
});

So far it shows up the Media modal with the images in there as I expected. The issue is when I upload a file by drag and drop it won't appear on the list of attachments view when the upload finishes, although it does upload the file. And it appears when the page is refreshed. https://share.getcloudapp.com/xQuY8gQW

I added one more state but without the 'category' in the query and when I do drag and drop, the image uploads as usual but it appears on the second tab.

Is there anything else I am missing? I tried reading the code for the options that the library receives and couldn't figure it out.

1 Answer 1

0

Found 2 other questions similar (almost the same?) as mine:

And found the solution in one of the comments in the latter. It links to a ticket and the last post has the solution to it:

var customMedia = wp.media({
    state: 'customState',
    states: [
        new wp.media.controller.Library({
            id: 'customState', 
            title: 'Library',
            library: wp.media.query({
                type: 'image',
                category: 'icon' // adding a filter to ajax_query_attachments_args
            }),
            multiple: false,
            date: false,
        })
    ]
});

// This will add the item uploaded to the list of attachments in the moodal 
customMedia.states.get('library').get('library').observe( wp.Uploader.queue );  

This won't fix the issue when opening the modal again. It doesn't show the images that were just added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.