Restrict the Search Results to Different Countries

If your locations are spread across the world, and you’ve created individual pages for each country, then it’s possible to restrict the search results on each page to a specific country.

The code below checks if the current page matches with either ‘store-locations-australia’ or ‘store-locations-germany’ ( replace this with the slug from your own pages ). When a match is found the results are restricted to the provided country code, which in the code below is either ‘au’ or ‘de’.

If no matches are found, then it will default to the map region set on the settings page.

Copy the code and place it in the functions.php inside your active theme folder.

If you prefer to restrict the results of the autocomplete option to different countries, then this requires the wpsl_autocomplete_options filter.

This only works if a default map region is selected on the settings page, and the “Restrict the geocoding results to the selected map region?” checkbox that shows up after selecting a map region is enabled as well.