I'm trying to use the Backbone, customizing the Author Filter in media library grid view.
I found lots of information on the Internet, and create filter on the toolbar. But there is one error I can't figure it out. The filter can't index + 1 for my items, I know there is a hidden item I need to add, but anything I tried can't achieve that.
Here is the code I tried.
(function(){
// create Author Filter
var MediaLibraryCustomFilter = wp.media.view.AttachmentFilters.extend({
id: 'media-attachment-custom-filter',
createFilters: function() {
var filters = {};
filters.all = {
text: 'Author',
props: {
author: "",
},
priority: 10
};
_.each( MediaLibraryCustomFilterData["author"] || {}, function( value, index ) {
filters[ index ] = {
text: value["display_name"],
props: {
// Change this: key needs to be the WP_Query var for the taxonomy
author: value["display_name"],
},
priority: 20
};
console.log(filters[ index ]);
});
this.filters = filters;
}
});
// create ToolBar
var AttachmentsBrowser = wp.media.view.AttachmentsBrowser;
wp.media.view.AttachmentsBrowser = wp.media.view.AttachmentsBrowser.extend({
createToolbar: function() {
// original toolbar
AttachmentsBrowser.prototype.createToolbar.call( this );
this.toolbar.set( 'MediaLibraryCustomFilter', new MediaLibraryCustomFilter({
// controller: this.controller,
model: this.collection.props,
priority: -75
}).render() );
}
});
})()
I already have the filter on the toolbar.
When I select the test 2 author, the result is still test 1.
Please help me for this error! Still can't find the answer on the Internet.