I want to get the total number of results after searching WordPress users by role and a string that matches the user name.
What I tried so far:
$args= array('echo'=>false, 'role' => 'author', 'search'=>$search_txt);
$user_query = new WP_User_Query($args);
$auth_count= $user_query->get_total();
But it returns 0 everytime.
Note:
Perhaps it can be done by:
$args= array('echo'=>false, 'role' => 'author', 'search'=>$search_txt);
$auth_count= count(get_users($args));
or by querying with
global $wpdb;
But is there any more resource friendly method?
$search_txt
. I'm not sure what else would explain getting zero results unless it really is zero results for your search ;-)