Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author webbistro

    (@webbistro)

    Hello,

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

    Nadia

    Thread Starter linsms

    (@linsms)

    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

    Plugin Author webbistro

    (@webbistro)

    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

    Thread Starter linsms

    (@linsms)

    It works, thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Open media selector with a filter’ is closed to new replies.