I am trying to devlope a plugin that will search and return my users so I can edit some other metatdata that belongs to them. I have been using the plug-in listed on the Codex as my starting point.

I have my table appearing with the the users from a WP_User_Query. But I am having issues with filtering the query with the search input.

Wildcard search mysearch will return the table correctly, but going to the second page returns back to a blank search. The search variable is not being placed in the url. How do I pass this to the url? (the pagination is passed only)

Also is there a way to change it so that I do not have to physically at "*" before and after the search parameters and have it done in the code?

Here is my query:

function prepare_items() {
    global $wpdb;

    $searchcol= array(

    $orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'email';
    $order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : 'ASC';

    $args  = array(
    'fields' => 'all_with_meta', 
    'orderby' => $orderby , 
    'order' => $order , 
    'search' =>$_REQUEST["s"] ,
    'search_columns' => $searchcol

    $my_query = new WP_User_Query( $args );

and here is my search field:

    function my_render_list_table_page(){
    global $my_list_table_sample_page, $wpdb;

    <form action="" method="post" >
   $my_list_table_sample_page->search_box( __( 'Search Users' ), 'user' ); 
   echo '</form>'; 
  • Found the parameter 'search_columns' for WP_User_Query then created an array with 'ID', 'user_email', 'user_login', 'user_nicename', 'user_url', 'display_name' for its parameters. Now to add wildcard to the search as it only returns full matches.
    – Ken
    Commented Aug 2, 2012 at 16:23
  • 2
    The search parameter is not being placed in the url because your form is using POST instead of GET.
    – Brian
    Commented Jan 24, 2013 at 8:46

2 Answers 2


Brian is correct. By changing the form to use get instead of post and then using $_REQUEST to fetch it should work, and is for me.

// Fetch, prepare, sort, and filter our data.
if( isset( $_REQUEST ["s"] ) ){

// Form that displays the table and also contains the search_box()
<form id="table-class-filter" method="get" class="table-class-admin-form">

As Brian noted, your form sends the data via POST, and you are fetching via GET. Change for method to "GET" or else use the $_POST variable. (But note that your search term is passed along using your current code, because both POST and GET populate the $_REQUEST variable).

You can make the search more flexible by ensuring that it is surrounded by wildcard (asterisk) characters. Something like this should do the trick:

$search = preg_replace( "^$\**(.*)\**$?#", "*$1*", $_REQUEST["s"] );

This will allow the search input was submitted with zero or more leading/trailing asterisks, and ensure that your search string is preceded and followed by a single asterisk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.