Title: pre_get_posts WP_User_Query
Last modified: October 27, 2020

---

# pre_get_posts WP_User_Query

 *  [Sean Turtle](https://wordpress.org/support/users/turts/)
 * (@turts)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/pre_get_posts-wp_user_query/)
 * I’m trying to run a custom search, which filters via an array set in ACF.
 * Essentially, I’m storing a list of users (contacts) in an array, and, if that
   is set, I want to search through those users, only.
 * I thought this would work:
 *     ```
       function searchfilter($query) {
         $my_contacts = array(11, 19); // setting just to check it's working
         $search_type = get_query_var('search_type');   
         if ($query->is_main_query() && $search_type == 'contacts' ) {
           $query->set('include', $my_contacts);
         }
   
         return $query;
         }
   
         add_filter('pre_get_posts','searchfilter');
       ```
   
 * But it doesn’t limit the query at all.
 * Appreciate any help!
    -  This topic was modified 5 years, 5 months ago by [Sean Turtle](https://wordpress.org/support/users/turts/).
    -  This topic was modified 5 years, 5 months ago by [Sean Turtle](https://wordpress.org/support/users/turts/).

Viewing 1 replies (of 1 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/pre_get_posts-wp_user_query/#post-13586807)
 * Your code is for searching posts, but your data is for users. Do you intend to
   search users or posts with those users as authors or something else?
    The `main_query`
   is for posts. So is the `pre_get_posts` filter. Also, query vars that are not
   known are removed, so if you are adding a new one, you have to “allow” it. See
   [https://developer.wordpress.org/reference/classes/wp/add_query_var/](https://developer.wordpress.org/reference/classes/wp/add_query_var/)
   and [https://developer.wordpress.org/reference/hooks/query_vars/](https://developer.wordpress.org/reference/hooks/query_vars/)

Viewing 1 replies (of 1 total)

The topic ‘pre_get_posts WP_User_Query’ is closed to new replies.

## Tags

 * [pre_get_posts](https://wordpress.org/support/topic-tag/pre_get_posts/)
 * [wp_user_query](https://wordpress.org/support/topic-tag/wp_user_query/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [Joy](https://wordpress.org/support/users/joyously/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/pre_get_posts-wp_user_query/#post-13586807)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
