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

});

Read more here: Show only images and videos in a wp.media window

Leave a Reply

Your email address will not be published. Required fields are marked *