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

  1. linsms
    Posted 2 years ago #


    I'm opening the media selector with:

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

    Greets & Thanks


  2. webbistro
    Plugin Author

    Posted 2 years ago #


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


  3. linsms
    Posted 2 years 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?


  4. webbistro
    Plugin Author

    Posted 2 years 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' );

    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.


  5. linsms
    Posted 1 year ago #

    It works, thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Enhanced Media Library
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic