Skip Navigation

[Resolved] Custom search including map/distance filter not working as expected

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a custom search View with a map and a distance filter. When I try to load the results on my staging site, no results appear.

Solution: In this case the addresses have not been geocoded in staging, so the distance filter calculations do not work. As a workaround, you could create a map with no distance filter that shows all the addresses. Load that map in the browser to trigger the geocode event.

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 7 replies, has 2 voices.

Last updated by Rob 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1390007

Rob

I am trying to:

Create a custom search for a properties list that includes a map search alongside a bunch of custom search filters, such as property type, min bedrooms, etc.

We have a custom post type (from Types) called properties, which have a bunch of custom fields, into which data is imported via WP All Import on a regular basis (via a cron job that runs overnight).

I've created a new page with the views shortcode 'property-search' on it and it's outputting the filter on the front end.

Link to a page where the issue can be seen:

You can view the page here - hidden link

I expected to see:

When you perform a search, including a location and radius distance, that a list of properties would be returned onto the page which are within the search fields' parameters set by the user. For example, if I enter 5 miles of Selby, UK, 3 min beds, and 'house' as a property type, I would expect a number of properties with meeting those crieritia to be displayed on the page.

Instead, I got:

So, there are a few issues happening:

1. Currently, the only thing you can get is a 'no items found' message, no matter what you do. This DID previously, at least, load some properties

2. When the search DID work, the properties that are returned had almost nothing to do with the search terms selected -- i.e. it seemed to be the same bunch of properties

3. Not all properties were returned. There are currently 67 ish property posts but it would only ever list something like 43 ish. Is there a caching conflict perhaps?

4. The location search definitely doesn't match what's entered. If you look at any property item in the back end, you'll see it has a 'location' field which is populated. It also shows the Google Map location on there, which suggests the address has been geocoded correctly. However, you can search for things on the front end with a location and distance and it doesn't seem to tie together with the results.

Please excuse the styling of the distance search fields, it's a work in progress.

#1390525
Screen Shot 2019-11-24 at 11.24.22 AM.png

Hi, it looks like there is an API Key issue in staging. Please go to wp-admin > Toolset > Settings > Maps, and click "Check API". I received an error that the request was denied because there is a referrer restriction in place in the Google Maps API console. That restriction should be removed, and a second API key can be used for security instead as described in our documentation: https://toolset.com/documentation/user-guides/display-on-google-maps/creating-a-google-maps-api-key

Let's correct that issue first, then I can continue to debug any outstanding issues with this search View.

#1392383

Rob

Thanks Christian. Apologies for the delay, I'm working with a client who's responsible for providing the API keys and such, so I've informed them of your response and I'll come back to your once we've got an updated key that stops displaying an error.

#1392405

Rob

Hi again Christian,

I've been supplied with a new, unrestricted maps API key which has been added to the site and checks out OK.

#1392643

It looks like most of the locations had not been geocoded by the Google Maps API. This can happen if the database cache is deleted and the custom field values are imported or migrated from another site. Since there was a distance filter applied to the View but no geocoded addresses, none of the properties were appearing in the results. Then I edited some of the properties in the backend, but I didn't make any changes. That was enough to trigger the geocoding process for each of those locations, and those properties began to appear in the results. I took the liberty of opening each Property post in wp-admin to trigger the geocoding process, and I see more results appear in the View now. Can you confirm things are working more like expected now?

#1393203

Rob

Ahh that looks tons better. Seems to be working too (as in bringing back the correct properties according to the radius/location set). Huge huge thanks for that.

The properties are indeed imported via a cron job that runs each day. When properties are imported, do we have to then go into each new property that's added, and just save/update it for it to be brought into the front end?

#1393279

You'll have to trigger the geocoding event somehow before imported addresses will be available to a distance filter. Opening the post in wp-admin would do that, or displaying the address as a marker on a map (with no distance filter) would also work. In theory, you could create a hidden page or something that includes a map with no distance filter and use a cron to hit that page after the import process. That would trigger the geocode event for the new addresses. It might take multiple cron hits since Google Maps imposes limits on how many addresses you can geocode in a short amount of time. I think it's 10/second.

If the single post template includes a map with a marker for this address, loading each single post page would trigger the geocode event as well. I'm not familiar with your site so I'm not sure how it's configured.

#1393327

Rob

Brill, thanks for that Cristian and all your help. I'll see if the client can set up a cron job and I'll create a hidden map page as you suggested