最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

author - Media Library Grid View Custom Filter

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论