2

Using wp.media function to create custom uploader popup I can't find argument to show attachment filters.

if(typeof wp === 'undefined' || typeof wp.media === 'undefined') {
  return false;
}

var frame = wp.media({
   title: 'Custom title',
   multiple: false
});

My result:

enter image description here

Desired result:

enter image description here

Any help will be appreciated

1 Answer 1

4
+50

You need to make use of filterable property. To do that, you can extend the library and use that as a custom state.

// Create state
var myCustomState = wp.media.controller.Library.extend({
    defaults :  _.defaults({
        id: 'my-custom-state',
        title: 'Upload Image',
        allowLocalEdits: true,
        displaySettings: true,
        filterable: 'all', // This is the property you need. Accepts 'all', 'uploaded', or 'unattached'.
        displayUserSettings: true,
        multiple : false,
    }, wp.media.controller.Library.prototype.defaults )
});

//Setup media frame
frame = wp.media({
    button: {
        text: 'Select'
    },
    state: 'my-custom-state', // set the custom state as default state
    states: [
        new myCustomState() // add the state
    ]
});
1
  • It works! Thank you. I will send your bounty asap Jul 22, 2019 at 22:31

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.