Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

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

get_users(
   'meta_key' => 'town',
   'meta_value' => $town,
   'meta_compare' => '='
);
share|improve this answer
    
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. –  Andrei Gheorghiu Oct 10 '12 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. –  Hameedullah Khan Oct 11 '12 at 8:15
add comment

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 ) );
share|improve this answer
    
This looks like what I was looking for. I'll give it a spin and get back with feedback. Thank you very much. –  Andrei Gheorghiu Oct 10 '12 at 22:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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