I have filtered posts, pages and custom_post_types based on $current_user custom usermeta field values using pre_get_posts().

Is there a similar method/function to alter get_users() based on $current_user custom field values? I've searched quite a bit but came up empty handed.

For example, let's assume I want to filter the results of get_users() for an editor with the "town" custom meta of "Paris" to only return the list of users with the same value in "town" field. Similarly, an editor with "Rome" in "town" should get only users from "Rome", and so on...

Ideally, I'd like this parameter to append itself to all get_users() done by the website's functions in both back and front end as long as the user is logged in.

Is this possible in WordPress?

Thank you.

2 Answers 2


There's the pre_user_query action called in the prepare_query() method of the WP_User_Query class defined in wp-includes/user.php:

do_action_ref_array( 'pre_user_query', array( &$this ) );
  • This looks like what I was looking for. I'll give it a spin and get back with feedback. Thank you very much. Oct 10, 2012 at 22:02

Suppose you have the $current_user town saved in a variable $town. The meta key is town. You can use get_users like following:

   'meta_key' => 'town',
   'meta_value' => $town,
   'meta_compare' => '='
  • In order to apply this to every use of get_users, I'd have to alter all plugins who use the function, so I won't be able to update them. I was looking for something that would append query vars to any use of get_users made by plugins and even core, depending on $current_user custom meta value. Oct 10, 2012 at 22:00
  • You ant to alter all the call for get_users? Maybe I missed it in the question. Let me get back to you with the solution to that. Oct 11, 2012 at 8:15

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.