Title: Taxonomy List Filter Based on Example Plugin
Last modified: September 1, 2016

---

# Taxonomy List Filter Based on Example Plugin

 *  Resolved [Julie](https://wordpress.org/support/users/habannah/)
 * (@habannah)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/taxonomy-list-filter-based-on-example-plugin/)
 * Hi David,
 * I’ve been learning more and more about MLA and have figured out how to implement
   and customize a few of your example plugins. Thanks for all the effort you put
   into creating all of those; it’s been a good way for me to learn.
 * I’m just having a bit of a hard time getting the `list-table-extranav-example`
   to work for me. I changed it to use `wp_dropdown_categories` instead, and adjusted
   the arguments accordingly. The filter appears and displays correctly at `/upload.
   php?page=mla-menu`, but if I select a term and click the Filter button, the page
   reloads without doing anything, and the filter resets itself to “All”.
 * I’m hoping you wouldn’t mind having a quick look at my plugin to see if you can
   catch anything. Since it’s a bit long for the forum, I’ve put it up [on Pastebin](http://pastebin.com/jv1Lts2Z).
 * Many thanks!!
 * [https://wordpress.org/plugins/media-library-assistant/](https://wordpress.org/plugins/media-library-assistant/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Julie](https://wordpress.org/support/users/habannah/)
 * (@habannah)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/taxonomy-list-filter-based-on-example-plugin/#post-7612985)
 * Perhaps I should specify that it’s because I want to have two taxonomy filters
   available, and I don’t like constantly having to go to the settings screen to
   switch. If the filters can work together like the others do, that would be great,
   but if not, it’s not the end of the world.
 * And also probably relevant is that the filter I created is calling a custom attachment
   taxonomy which I registered in my theme.
 * Thanks 🙂
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/taxonomy-list-filter-based-on-example-plugin/#post-7613152)
 * Thanks for an interesting adaptation of the `list-table-extranav-example` example
   plugin and for your question. Your additional taxonomy filter should be of interest
   to other MLA users as well.
 * The original example you started from added an “Author” dropdown control. The“
   Author” filter already existed as a standard MLA filter (click on an author name
   in the table column), so the logic had to distinguish between the existing filter
   and the new dropdown control. Your adaptation is adding an entirely new filter,
   so the logic is somewhat different.
 * Briefly, your filter isn’t working because there’s no code to use the selected
   value to add a taxonomy query to the filters for the submenu table.
 * I made two changes to your plugin. First, I made a change towards the bottom 
   of the  function to properly display the “No Places” (value ‘-1’) option. Look
   for:
 *     ```
       if ( isset( $_REQUEST['place'] ) && $_REQUEST['place'] > '0' ) {
       ```
   
 * and change it to:
 *     ```
       if ( isset( $_REQUEST['place'] ) && $_REQUEST['place'] !== '0' ) {
       ```
   
 * Second, I replaced the entire `mla_list_table_query_final_terms` function with
   a new version that handles the taxonomy query addition. Here’s the complete source
   code for the new function:
 *     ```
       /**
            * Add 'place' taxonomy query to the query parameters
            *
            * @since 1.01
            *
            * @param    array    $query_terms    Current query parameters.
            */
           public static function mla_list_table_query_final_terms( $query_terms ) {
               if ( isset( $_REQUEST['place'] ) ) {
                   // Ignore "All Places"
                   if ( 0 == $place = intval( $_REQUEST['place'] ) ) {
                       return $query_terms;
                   }
   
                   $tax_filter = 'place';
                   if ( -1 == $place ) {
                       $term_list = get_terms( $tax_filter, array(
                           'fields' => 'ids',
                           'hide_empty' => false
                       ) );
                       $place_query = array(
                           array(
                               'taxonomy' => $tax_filter,
                               'field' => 'id',
                               'terms' => $term_list,
                               'operator' => 'NOT IN'
                           )
                       );
                   } else {
                       $place_query = array(
                           array(
                               'taxonomy' => $tax_filter,
                               'field' => 'id',
                               'terms' => array( $place ),
                               'include_children' => false,
                           )
                       );
                   }
   
                   if ( isset( $query_terms['tax_query'] ) ) {
                       $query_terms['tax_query']['relation'] = 'AND';
                   } else {
                       $query_terms['tax_query'] = array();
                   }
   
                   $query_terms['tax_query'][] = $place_query;
               } // isset place
   
               return $query_terms;
           } // mla_list_table_query_final_terms
       ```
   
 * I hope you can incorporate those changes in your plugin and get something that
   works for your application. I am marking this topic resolved, but please update
   it if you have problems or further questions regarding the suggested solution.
   Thanks for a great example of extending the Media/Assistant navigation options.
 *  Thread Starter [Julie](https://wordpress.org/support/users/habannah/)
 * (@habannah)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/taxonomy-list-filter-based-on-example-plugin/#post-7613196)
 * Thanks so much for this, David!! It looks like it was more involved than I imagined…
   I implemented your changes and tested things out, and everything works perfectly!
   I can’t thank you enough 🙂
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/taxonomy-list-filter-based-on-example-plugin/#post-7613197)
 * You are most welcome. As I said, this is a great example of extending MLA that
   should be of general interest.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Taxonomy List Filter Based on Example Plugin’ is closed to new replies.

 * ![](https://ps.w.org/media-library-assistant/assets/icon-256x256.png?rev=973502)
 * [Media Library Assistant](https://wordpress.org/plugins/media-library-assistant/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-assistant/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-assistant/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-assistant/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-assistant/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-assistant/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [David Lingren](https://wordpress.org/support/users/dglingren/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/taxonomy-list-filter-based-on-example-plugin/#post-7613197)
 * Status: resolved