wpsl_geolocation_filter_pattern

  1. Description
  2. Usage
  3. Changelog
  4. Source File

Description

This filter allows you to change the pattern that’s used to filter out the location data from the Geocode API response.

This is necessary because the Geolocation API itself only returns a set of coordinates. To change this into a readable form, we need to send the coordinates to the Geocode API.

By default, it filters out the ‘postal_code’, ‘postal_code_prefix,postal_code’ value, but you can change this to the following values.

  • street_number
  • route
  • political
  • locality
  • administrative_area_level_2
  • administrative_area_level_1
  • country
  • postal_code
  • formatted_address

You can see an example of the returned data from the Geocode API here.

If the postal_code field is not included in the response, then it will default to the format_address field. This will show the address in this format: Oudezijds Achterburgwal 1921, 1012 DX Amsterdam, Netherlands.

Usage

add_filter( 'wpsl_geolocation_filter_pattern', 'custom_geolocation_filter_pattern' );

function custom_geolocation_filter_pattern() {

    $filter_pattern = array( 'formatted_address' );

    return $filter_pattern;
}

Changelog

Since 1.1.0 ( search widget only for now ).

Source File

This filter is located in /inc/class-widget.php

Placement

The code needs to be placed in the functions.php file inside your active theme folder.