Support » Developing with WordPress » Maximum number of additional arguments to meta_query?

  • Resolved kthorjensen

    (@kthorjensen)



    So here’s a thing I’m working on: using the Ultimate Member plugin, I’ve got a database of users that want to find each other by location. I installed a database of ZIP codes and lat / long values, and I take the inputted zip from the GET parameters in the URL, pass it to a function that does a little trig and grabs all ZIP codes in a radius around it and spits them back out as a big array to meta_query as sets of arguments with key=”user_zip”, value – a matching zip code and compare = “in”. And it works just fine!

    EXCEPT: if too many matching ZIP codes are returned, the query… borks out and returns nothing. This is not a problem in most of the United States except for New York City, where ZIPs are packed tight and steamy. So my question is: is there a hard limit to the number of variables you can pass to meta_query? And if so, can I change it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • There’s no hard limit, but meta queries are not very efficient. The way meta data is stored in WordPress is not terribly conducive to more complex queries or large amounts of data.

    The best solution here would be to store the zip data in a custom table where the zip codes are indexed. But this would require you to add custom arguments to WP_Query and add SQL for them using the posts_where and posts_join filters.

    A more immediate solution would be to limit the nearby zips to a smaller distance or lower number of zip codes.

    • This reply was modified 4 months, 1 week ago by  Jacob Peattie.
    RossMitchell

    (@rossmitchell)

    Another solution would be to hard code exceptions for the NYC codes and either limit the search radius or return a custom written one.

    kthorjensen

    (@kthorjensen)

    Thanks for the advice, both of you. What I ended up doing is adding another column to my ZIP / LAT / LONG table that indicates if the site has a member in that ZIP and then only returning those with the radius query, as well as reducing the radius. I’ll probably also hard-code NYC exceptions down the line. Much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.