admin管理员组

文章数量:1277373

I am creating a zip code radius search. I am pulling the all the zip codes within a radius depending on the search term through an API, then doing a user query to compare a custom meta field that has their zip and display those users if there is a match within the array of zip codes. I am doing this for both US/Canada. This is working except when I increase the radius and if that location happens to have a large amount of zip codes it breaks and no users are found. Especially in Canada there are literally thousands of zip code variations within just a 10km radius. For example if you look here .htm and search T5T 3E9 there are over 10k zip code results.

This only seems to be related to having a very large array. Any thoughts?

curl_setopt($ch, CURLOPT_URL, "?" . 
http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"apikey: ", ));

$zipresponse = curl_exec($ch);
curl_close($ch);

$json = json_decode($zipresponse);


$resultArray = json_decode($zipresponse, true);
$zipCodd = $resultArray['results'];


$newzipArray = array();
if ( !empty( $zipCodd ) ) {
    $i = 0;
    foreach($zipCodd as $data){
        $i++;
            $newzipArray[$i] = str_replace(' ', '', $data['code']);
    }
}

$user_search_args = array (
  'number'          => 50, // How many per users
  'role'            => 'subscriber',
  's'               => '*' . esc_attr( $search_term ) . '*',
  'meta_query'      => array(
     'relation'    => 'OR',
          array(
              'key'     => array('mepr-address-zip', 'mepr_second_location_zip_2','mepr_third_location_zip_3'),
              'value'   => $newzipArray,
              'compare' => 'IN'
          ),

      )
  );

$user_search_query = new WP_User_Query( $user_search_args );

本文标签: meta queryIssue with user metaquery