1

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:

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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