I've successfully created 3 taxonomies attached to the user object, using the registered_taxonomy and update_count functions of this code - https://gist.github.com/portfola/10750784#file-user-taxonomies-php (I don't need the rest as they're only relevant for taxonomies displaying an admin UI or taxonomy archive which I'm not). These taxonomies store which company, office and teams, each user is assigned to.
I know the custom taxonomies are storing the data as I get multiple results back via the wp_get_object_terms($user->ID,'company')
function.
What I need is to be able to filter the users.php results by either one of or multiple of these custom taxonomies. I've created the additional form inputs found at the WP_List_Table and have also added the columns for each taxonomy. The only thing left to do is modify the pre_user_query. I don't think this is the right way to do as it's not having any effect on the results returned at all and I'm only beginner of MySQL.
Here's my current code for modifying the query:
function preUserQuery($query) {
global $pagenow, $wpdb;
if(is_admin() && $pagenow == 'users.php') {
$query->query_vars['tax_query'] = array();
foreach(array('userCompany','userOffice','userTeam') as $queryVar) {
if(isset($_GET[$queryVar]) && is_numeric($_GET[$queryVar])) {
$query->query_vars['tax_query'][] = array(
'taxonomy' => get_post_type($_GET[$queryVar]),
'field' => 'name',
'terms' => $_GET[$queryVar]
);
}
}
}
return $query;
}
add_filter('pre_user_query','preUserQuery',9999);