Invalid Argument messages
-
Hi
I’ve added 30+ stores to our locator, but i’ve now started to get this message when saving:
Warning: Invalid argument supplied for foreach() in /home/wayne/public_html/wp-content/plugins/wp-store-locator/admin/class-geocode.php on line 157
Warning: Cannot modify header information – headers already sent by (output started at /home/wayne/public_html/wp-content/plugins/wp-store-locator/admin/class-geocode.php:157) in /home/wayne/public_html/wp-admin/post.php on line 242
Warning: Cannot modify header information – headers already sent by (output started at /home/wayne/public_html/wp-content/plugins/wp-store-locator/admin/class-geocode.php:157) in /home/wayne/public_html/wp-includes/pluggable.php on line 1207
This has only started once i’ve begun to enter our overseas distributors into the list, the UK is fine. However, i’m entering all the same info into the correct fields. I’ve tried entering other details, but it just refuses to save.
Any help appreciated.
Thanks
-
If you open the /admin/class-geocode.php and search for function geocode_location ( should be line 59 ).
The first line you see in the function should be this.
$geocode_response = $this->get_latlng( $post_id, $store_data );
Add this code just below it, save the file, and try to add another location.
echo '<pre>'; print_r( $geocode_response ); echo '</pre>'; exit();
This should show the returned data from the Geocode API, and any possible errors. If it’s not to much text, can you copy / paste it here, or otherwise take a screenshot of the returned data?
Thanks for the response, when i enter new data this is the response…
Array
(
[results] => Array
(
[0] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => Herning
[short_name] => Herning
[types] => Array
(
[0] => locality
[1] => political
))
[1] => Array
(
[long_name] => Herning Municipality
[short_name] => Herning Municipality
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
))
[2] => Array
(
[long_name] => Central Denmark Region
[short_name] => Central Denmark Region
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
))
[3] => Array
(
[long_name] => Denmark
[short_name] => DK
[types] => Array
(
[0] => country
[1] => political
))
[4] => Array
(
[long_name] => 7400
[short_name] => 7400
[types] => Array
(
[0] => postal_code
))
)
[formatted_address] => 7400 Herning, Denmark
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 56.2819932
[lng] => 9.1831637
)[southwest] => Array
(
[lat] => 55.9786648
[lng] => 8.760286
))
[location] => Array
(
[lat] => 56.138557
[lng] => 8.967322
)[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 56.2819932
[lng] => 9.1831637
)[southwest] => Array
(
[lat] => 55.9786648
[lng] => 8.760286
))
)
[partial_match] => 1
[place_id] => ChIJ_SOAS3G8S0YRasgKh297ivI
[types] => Array
(
[0] => locality
[1] => political
))
[1] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => 7400
[short_name] => 7400
[types] => Array
(
[0] => postal_code
))
[1] => Array
(
[long_name] => Herning
[short_name] => Herning
[types] => Array
(
[0] => locality
[1] => political
))
[2] => Array
(
[long_name] => Denmark
[short_name] => DK
[types] => Array
(
[0] => country
[1] => political
))
)
[formatted_address] => 7400 Herning, Denmark
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 56.2819932
[lng] => 9.1831637
)[southwest] => Array
(
[lat] => 55.9786648
[lng] => 8.760286
))
[location] => Array
(
[lat] => 56.1255662
[lng] => 8.9496583
)[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 56.2819932
[lng] => 9.1831637
)[southwest] => Array
(
[lat] => 55.9786648
[lng] => 8.760286
))
)
[partial_match] => 1
[place_id] => ChIJ7eq43om7S0YR31Pa3rI36Ek
[types] => Array
(
[0] => postal_code
))
)
[status] => OK
)And if you remove the extra code, and try it again for the same address, it still comes up with the invalid argument error? Just to be sure, you didn’t click the “Preview Location” button in the editor?
After adding that code and adding the new entry above then when i do in a search on the website it doesn’t show the result. but at the same time doesn’t show “no results found” as i would usually get.
So, removing all that code and trying again…
It works! No idea what happened there then.
Wayne
You are not the first one to run into that error, just never really been able to figure out how it happens. It almost looks like the Geocode API sometimes returns data without the coordinates, but sets the status field to OK. That really shouldn’t happen.
At least it works again, I will see if I can code something around it in case the coordinate fields are really empty.
Sadly it doesn’t work again! Well, i can input the data, but it’s now not showing any results when i look online, doesn’t even give me the “no result found” screen.
Did you set a large enough search radius? What’s the url, and where should I search for?
Yes, I set it for 500 miles (is there a way of removing the search size area?)
If you look here for “Liverpool” then it should show no results:
https://scarechasers.com/~wayne/where-to-buy/
Thanks
Wayne
If you look here for “Liverpool” then it should show no results:
If I search for Liverpool it does return “Do Good Audio”, why is this wrong? You can disable all the dropdowns on the settings page -> search section.
If you search for something again, and it doesn’t return any results, and also no “No results found”. Can you check for JS errors. Maybe one of the scripts sometimes triggers an JS error.
- The topic ‘Invalid Argument messages’ is closed to new replies.