I have a custom search query based on a radius search. There is an adress field that has a postal code value in it. This postal code is being copied from another field when the post is saved.
However sometimes the postal code is copied as is, example given: 1234 AA . If this is the case the post can be found in the search on the frontend.
But sometimes when the postal code is saved in the adress field it has extra data in it, example given: 1234 AA [city], [Country]
If these values are added in the adress field the post will NOT show up while searching for the specific post.
Any idea why this is happening and is possible is there a way to prevent this from happening?
Note: the source field only contains the postal code, not the city and or country!
There is an adress field that has a postal code value in it. This postal code is being copied from another field when the post is saved.
How exactly is the field value copied from another field? Please provide any custom code you have used for me to review. I'm not sure why the city and country would be added automatically like this. Manipulating address field values programmatically is generally not a good idea since the new address isn't validated ahead of time, but maybe I can spot something unusual in the code.
Hi Christian,
Thanks for the quick reply!
this is the code I am using:
add_action( 'save_post', 'copy_location_to_multiline_field_admin', 100, 3 );
function copy_location_to_multiline_field_admin( $post_id, $post, $update ) {
if ( $post->post_status == 'publish' && $post->post_type == 'post' ) {
$location = get_post_meta( $post_id, 'postalCode', true);
update_post_meta( $post_id, 'wpcf-postcode', $location );
}
}
Okay thanks. Can you provide examples of one or two addresses that now have the city and country added in the wpcf-postcode address field, even though the corresponding postalCode field does not contain that information? I will run some tests locally and see if I can replicate the problem.
the postal code 3888 LL is from the source field
the value in the custom field data: wpcf-postcode is also 3888 LL
the value after the geocoding 3888 LL Uddel, Nederland in the toolset adress field
another example is 3846 AX
an example of a postal code that works ok: 3845 CA
For some etra information: these are all dutch postal codes.....
Thanks again for looking into this!
If you need any more information I will be happy to provide you with it.
Just wondering: If its not possible to show / transfer only the postal code, is it the possible to make the radial search work with fields that have postal code only and fields with postal code + city + country? That would be a fix also I think.
is it the possible to make the radial search work with fields that have postal code only
You must use geocoded locations in a Toolset address field to implement accurate distance-based searches. Postal code only usually isn't sufficient.
May I log in and see how this View is set up? Please let me know how I can find the View on the front-end of the site.
By the way the posts where only the postal code is being used are accurate enough. It should not be too accurate, just roughly is more then enough 🙂
But the issue remains that only posts with just the postal code show up in the search and the posts with more information just do not despite the more accurate geolocation
AS you can see in post 905, this address "3845 CA" has not been geolocated. On my local machine, the map is pointing to California, not anywhere in the Netherlands. Where do you expect the marker to be shown?
Ah I see....it should be here 3845 CA Harderwijk.....
Is this the reason why the post is not showing? Because some do, some dont. On the frontend on the greenmonkeys.nl/vacatures only 18 posts are showing instead of 62 if you enter no search criteria
Yes, I suspect this is at least part of the reason why the distance-based searches are not performing as you would expect. Without geocoding, the distance filter cannot complete its calculations...the addresses are too ambiguous.
Allright, so if i update all posts manually with complete geocoding it should work? Maybe I should ditch the information that is imported and make it manual labour. Maybe this is not to be automated?
I think it should work, but you should try a small-scale experiment to be sure. There are other variables to consider.
I would not rely on automated address field information - it is not specific or unique enough. It is best to select a location from the auto-suggested options, or validate each entry some other way with the Maps API and your own custom code.
Hi Christian,
Just did some further testing on a staging environment and removing the code that copies the data in the toolset field and then manually update the geolocation fixes all problems so far. Will do some further testing but thinks look good now. I would like to thank you very much for thinking along and guiding me to the cause and the solution of this problem! I will remove access to the site now.
Thanks again and have a good day!
Kind regards,
Wim
My issue is resolved now. Thank you very much Christian!