0

I’m trying to run a custom user 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!

1
  • 1
    pre_get_posts is for posts not users, you can't use it for WP_User_Query
    – Tom J Nowell
    Oct 27 '20 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.