Title: [Plugin: Custom List Table Example] Add custom filter
Last modified: August 20, 2016

---

# [Plugin: Custom List Table Example] Add custom filter

 *  [shinji251184](https://wordpress.org/support/users/shinji251184/)
 * (@shinji251184)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-add-custom-filter/)
 * This plugin is perfect to create new admin screens 😉
    There’s a example of how
   to add a “builk action” (delete…) but I need to add a custom filter and I had
   some problem because I don’t know how to put the code.
 * Here is what I wrote. :
 *     ```
       function get_bulk_actions() {
         $actions = array(
         // I don't need to delete post in my case
         //'delete'    => 'Delete'
         );
   
         // Display date
         // For this example, I use a fonction in class-wp-liste-table.php
         // that display months (I use my own function to display months but this one works for the example)
         $this->months_dropdown('post');
         submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
   
         return $actions;
       }
       ```
   
 * This code displays a drop-down list with months with a submit button.
    But when
   I submit, I have some url parameters (get) that shouldn’t have to be there.
 * _admin.php?page=tt\_list\_test&\_wpnonce=f008999aef&\_wp\_http\_referer=%2Fwp-
   admin%2Fadmin.php%3Fpage%3Dtt\_list\_test_
 * _wpnonce & _wp_http_referer shouldn’t have to be url parameters.
 * And if I sort a column and change the month, it loses the order
 * Order :
    _/admin.php?page=tt\_list\_test&orderby=nom&order=desc_ => Change date:_/
   admin.php?page=tt\_list\_test&\_wpnonce=f008999aef&\_wp\_http\_referer=%2Fwp-
   admin%2Fadmin.php%3Fpage%3Dtt\_list\_test%26orderby%3Dnom%26order%3Ddesc&m=201111&
   paged=1_
 * Thank for your help.
 * [http://wordpress.org/extend/plugins/custom-list-table-example/](http://wordpress.org/extend/plugins/custom-list-table-example/)

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

 *  [David Gard](https://wordpress.org/support/users/duck_boy/)
 * (@duck_boy)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-add-custom-filter/#post-2465876)
 * I think that you need to add `$this->months_dropdown()` in the `extra_tablenav()`
   function.
 *  Thread Starter [shinji251184](https://wordpress.org/support/users/shinji251184/)
 * (@shinji251184)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-add-custom-filter/#post-2465877)
 * I tried what you say, but the problem was that in extra_tablenav, input are generated
   twice (and so the $_GET parameters, maybe I did it wrong) and I use a custom 
   function to generate month (every months, not only months when posts are published).
 * Here’s a solution (I’m not sure if the code is in the right place) :
 *     ```
       function get_bulk_actions() {
           // function to generate month
           $this->month_select();
           return $actions;
       }
       ```
   
 * So my <select> appears inside the <form> in the right place.
 * And I wrote this code at the beginning of the plugin, under _require(ABSPATH .‘/
   wp-load.php’);_, to avoid url parameters trouble :
 *     ```
       require(ABSPATH . 'wp-includes/pluggable.php');
   
       if ( ! empty($_REQUEST['_wp_http_referer']) && $_REQUEST['page']=='tt_list_test') {
       $url_page_admin = stripslashes($_SERVER['REQUEST_URI']);
       wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
       exit;
       }
       ```
   
 * And finaly, I add some _input type=”hidden”_ and put order and orderby value,
   that disapear with redirection :
 *     ```
       if ( ! empty( $_REQUEST['orderby'] ) )
                       echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
                   if ( ! empty( $_REQUEST['order'] ) )
                       echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
       ```
   
 *  [Alex-A](https://wordpress.org/support/users/alex-a-1/)
 * (@alex-a-1)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-add-custom-filter/#post-2465920)
 * Hi There,
 * I just had a ‘WTF is going on session’ for a couple of hours dealing with the
   same issue. I also had the same problem that my custom filter was generated twice
   when i used it.
 * But! i’ve found the solution!! So i thought i would share it.
 * First thing is that you DO need to use extra_tablenav() for adding extra custom
   filters.
 * Now the reason WHY in that place the input is called twice, is because the extra_tablenav()
   generates the input twice ( at the top of the table and bottom ), so if you only
   provide one form or select field, the same parameter get called twice ( top /
   bottom ).
 * And when putting out a request every input is collected and put out.
 * To deal with that you have to provide a different input name for top and bottom,
   OR only put your filter at the top.
 * Do this so, by using the extra_tablenav() on the following way:
 *     ```
       function extra_tablenav($which) {
       	if ( $which == "top" ){
       // GENERATE FILTER FOR TOP
       }
       	if ( $which == "bottom" ){
       // FILTER FOR BOTTOM
       }
       }
       ```
   
 * But like i said, you also could only use one of them ( top bottom )
 * Hope it helps someone!
 *  [designerken](https://wordpress.org/support/users/kcharity/)
 * (@kcharity)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-add-custom-filter/#post-2465971)
 * [@shinji251184](https://wordpress.org/support/users/shinji251184/)
    I too have
   the issue with the _wpnonce and the _wp_http_referer appearing in the URL. The
   $_SERVER[‘REQUEST_URI’] doubles on itself and eventually I get the error that
   the URL is too long.
 * I am not too clear on where you put the code:
 *     ```
       require(ABSPATH . 'wp-includes/pluggable.php');
   
       if ( ! empty($_REQUEST['_wp_http_referer']) && $_REQUEST['page']=='tt_list_test') {
       $url_page_admin = stripslashes($_SERVER['REQUEST_URI']);
       wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
       exit;
       }
       ```
   
 * Could you make a pastebin?

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

The topic ‘[Plugin: Custom List Table Example] Add custom filter’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-list-table-example.svg)
 * [Custom List Table Example](https://wordpress.org/plugins/custom-list-table-example/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-list-table-example/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-list-table-example/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-list-table-example/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-list-table-example/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [filtering](https://wordpress.org/support/topic-tag/filtering/)
 * [url](https://wordpress.org/support/topic-tag/url/)

 * 4 replies
 * 4 participants
 * Last reply from: [designerken](https://wordpress.org/support/users/kcharity/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-custom-list-table-example-add-custom-filter/#post-2465971)
 * Status: not resolved