Media Manager (since 3.5): How to show an empty Media Library when creating a media frame?

Is there a way to make sure the “Media Library” tab does not show any images until I start uploading some in the “Upload Files” tab?

I am creating a wp.media frame with the following code:

Read More
var myframe =  wp.media({
    title : 'Bla Bla',
    frame : 'select',
    library: {
        //query : false, // not working
        type : 'image',
    },
    //library : '', // not working either
    multiple : true,
    button : { text : 'Finish' },   
});

It creates this:
Media Library with all items ever uploaded

Is there a way to make sure the “Media Library” tab does not show any images until I start uploading some in the “Upload Files” tab? And then obviously only shows those images that I just uploaded from the “Upload Images” tab.

Related posts

1 comment

  1. It’s not a pretty solution but I used the post__in attribute for this once in a custom plugin. Basically you usually define an array of attachment id’s to show in the media library.

    library: {
            type: 'image', post__in:[23,25,26]  // or a javascript variable that contained the array of id's
        }
    

    My code was originally built for that at that time. This was great for posts where the attachments were already attached to the post. But then I needed to show nothing for new posts. And what happened was that if the javascript variable containing the id’s was empty it would show the entire contents of the media library instead.

    I figured I could try using a hardcoded id which certainly had no attachment associated with it. So I did this:

    library: {
                type: 'image', post__in:[0]  // zero just to be sure
            }
    

    And by God, it worked. I hope it does for you aswell.

Comments are closed.