[wp-trac] [WordPress Trac] #37485: Custom filter in users list

WordPress Trac noreply at wordpress.org
Wed Jul 27 13:43:30 UTC 2016


#37485: Custom filter in users list
------------------------------+-----------------------------
 Reporter:  sebastian.pisula  |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Users             |    Version:
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 I have example code:

 {{{#!php
 <?php

 function admin_users_filter( $query ){
         global $pagenow,$wp_query;

         if ( is_admin() && $pagenow=='users.php' && isset($_GET['abc']) &&
 $_GET['abc'] != '') {
                 $query->search_term = urldecode($_GET['abc']);

                 global $wpdb;

                 if (!is_null($query->search_term)) {

                         $query->query_from .= " INNER JOIN
 {$wpdb->usermeta} ON " .
 "{$wpdb->users}.ID={$wpdb->usermeta}.user_id AND " .
 "{$wpdb->usermeta}.meta_key='meta_key_name_here' AND
 "."{$wpdb->usermeta}.meta_value LIKE '%{$query->search_term}%'";

                 }
         }
 }

 add_filter( 'pre_user_query', 'admin_users_filter' );


 add_action( 'restrict_manage_users', 'restrict_abc_manage_list' );
 function restrict_abc_manage_list()
 {
         ?>
         <select name="abc" style="float: none;">
                 <option value=""><?php _e('Filter By College', 'baapf');
 ?></option>
                 <option value="1">1</option>
                 <option value="2">2</option>
                 <option value="3">3</option>

         </select>
         <input id="post-query-submit" class="button" type="submit"
 value="Filter" name="">
         <?php
 }

 }}}

 Source: http://stackoverflow.com/a/20520947

 But variable "abc" have empty value. WTF?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37485>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list