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(
'ID',
'user_email',
'user_login',
'user_nicename',
'user_url',
'display_name'
);
$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;
$my_list_table_sample_page->prepare_items();
<form action="" method="post" >
<?php
$my_list_table_sample_page->search_box( __( 'Search Users' ), 'user' );
$my_list_table_sample_page->display();
$my_list_table_sample_page->display();
echo '</form>';
}
2 Answers
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">