Show only images and videos in a wp.media window

I’m using the following JS code to open a wp.media window to allow users to select images and videos for a gallery. Everything is working as expected, but I’m unable to restrict the window to show images and videos only, it’s showing everything.

Any ideas on what might be wrong?

Thanks in advance

JS:

$( '#add_item' ).on( 'click', function( e ) {
    var $el = $( this );

    e.preventDefault();

    // If the media frame already exists, reopen it.
    if ( items_frame ) {
        items_frame.open();
        return;
    }

    // Create the media frame.
    items_frame = wp.media.frames.items = wp.media({
        title: 'Add to Gallery',
        button: {
            text: 'Select'
        },
        states: [
            new wp.media.controller.Library({
                title: 'Add to Gallery',
                filterable: 'all',
                type: ['image', 'video'],
                multiple: true
            })
        ]
    });

    // Finally, open the modal.
    items_frame.open();

});

2 s
2

It’s been a while since this question was asked, but on the off chance that you are still looking for a solution:

items_frame = wp.media.frames.items = wp.media({
    title: 'Add to Gallery',
    button: {
        text: 'Select'
    },
    library: {
            type: [ 'video', 'image' ]
    },
});

Leave a Comment