WordPress.org

Ready to get started?Download WordPress

Forums

Enhanced Media Library
[resolved] Open media selector with a filter (5 posts)

  1. linsms
    Member
    Posted 4 months ago #

    Hello,

    I'm opening the media selector with:
    parent.wp.media.editor.open('nothing');

    There is a way to open it with a category selected?

    Greets & Thanks

    http://wordpress.org/plugins/enhanced-media-library/

  2. webbistro
    Member
    Plugin Author

    Posted 4 months ago #

    Hello,

    Please clarify your needs. What do you mean by "category selected"? And please give me more code and context.

    Nadia

  3. linsms
    Member
    Posted 4 months ago #

    Hello Nadia,

    What I would want to achieve is that when I click on a button and the wp.media.editor.open function is called, a preselected category appears in the image selector of the popup that's opened. This category would be sent as a parameter in the open function call.
    Would this be possible?

    Thanks

  4. webbistro
    Member
    Plugin Author

    Posted 4 months ago #

    Hello @linsms,

    You have to change code in plugin's file js/eml-media-uploader.js

    Replace whole media.view.AttachmentFilters.Taxonomy function (line 8) with following code (new version of the plugin will also work this way, so you can upgrade it in due time):

    // Taxonomy AttachmentFilters
    media.view.AttachmentFilters.Taxonomy = media.view.AttachmentFilters.extend({
    	tagName:   'select',
    
    	createFilters: function() {
    		var filters = {};
    		var that = this;
    
    		_.each( that.options.termList || {}, function( term, key ) {
    			var term_id = term['term_id'];
    			var term_name = $("<div/>").html(term['term_name']).text();
    			filters[ term_id ] = {
    				text: term_name,
    				priority: key+2
    			};
    			filters[term_id]['props'] = {};
    			filters[term_id]['props'][that.options.taxonomy] = term_id;
    		});
    
    		filters.all = {
    			text:  that.options.termListTitle,
    			priority: 1
    		};
    		filters['all']['props'] = {};
    		filters['all']['props'][that.options.taxonomy] = 0;
    
    		this.filters = filters;
    	},
    });

    Also add something like this in your js:

    wp.media.editor.open( 'test_id' );
    $('.attachment-media_category-filters').val(4).change();

    You have to replace media_category with your taxonomy name, and 4 with ID of its term.

    It's not a perfect solution, but it works right now.

    Nadia

  5. linsms
    Member
    Posted 4 months ago #

    It works, thanks a lot!

Reply

You must log in to post.

About this Plugin

About this Topic