Integration: GeoFilters

What it does

When mam-geofilters is also active, mam-geodirectory takes over the geofilter city list entirely. It subscribes to mam_geofilter_list (a filter owned by mam-geofilters) and replaces the built-in 55-city list with a deduplicated set of cities derived from your actual GeoDirectory listings.

The result: instead of the geofilter picker showing San Jose, Oakland, New York, etc. by default, it shows whatever cities your directory actually has listings in.


Activation

Two things must be true:

  1. mam-geofilters is active and geofiltering is turned on for the current role (tsl-use_geofilters is yes).
  2. mam-geodirectory is active.

When both are true, the plugin’s mam_geofilter_list callback runs (priority 10). When mam-geofilters detects that mam_geofilter_list has any subscriber, it skips the entire default-list path — see Hook: mam_wc_geofilters_locations in the geofilters plugin for the upstream gating.


How the city list is built

mam_geodirectory_manager::mam_geofilter_list($list):

  1. Iterates every registered GD post type, skipping gd_event.

  2. For each post type, queries {prefix}{post_type}_detail:

     SELECT DISTINCT city, region, latitude, longitude
     FROM {prefix}{post_type}_detail
     WHERE city IS NOT NULL AND city <> ''
  3. Skips rows with empty latitude or longitude.

  4. Builds a display label: '{city}, {convert_state(region)}' — converting region names to two-letter US/Canada abbreviations via the same convert_state() helper used elsewhere in the plugin.

  5. Deduplicates by formatted label.

  6. Appends entries to $list['geoFiltersLocations'] as {text, lat, lon}.

The table-existence check (SHOW TABLES LIKE %s) is run before each query so the callback safely no-ops on installations that have a registered post type without an underlying detail table.


What the app receives

The geofilter picker’s data comes from geoFiltersLocations. After this integration runs, that array is no longer the built-in 55 cities — it is your directory’s distinct cities.

The picker behavior on top is unchanged:

  • A “Current Location” entry can be prepended (controlled by gd-show-current-location-on-app — when not 'no', GPS-aware devices see this option).
  • A GeoIP-derived entry can be prepended when GPS is unavailable.
  • The cities array is sorted/displayed by the geofilters plugin per its own rules.

Things to watch for

  • Listings with empty region still produce labels like 'Brooklyn, ' (trailing comma). The plugin does not strip these. If your data has empty regions, expect cosmetic issues until they are filled in.
  • Custom abbreviations. convert_state() maps a fixed list of US states/territories and Canadian provinces. Anything else falls through to ucfirst($state). If your directory has international listings, the labels will look like 'Paris, Paris' (or similar) rather than abbreviated.
  • Distinct queries can be slow. A directory with millions of listings will spend non-trivial time on the DISTINCT query. The plugin runs it on every phone-data request — there is no cache. Consider an object-cache wrapper if this becomes a hot path.
  • Custom GD post types are included automatically except gd_event. To exclude additional post types, hook a callback at lower priority on mam_geofilter_list and remove unwanted entries.

Steps to take advantage

This is automatic. Activate both plugins and the integration is on. Configure the geofilter UI’s behavior on the mam-geofilters side — see Recipe: Enable geofilters in that plugin’s docs.

If you want to keep the built-in 55 cities in addition to yours, this integration is not the right path. The default-list path is short-circuited as soon as mam_geofilter_list has any subscriber. To merge your cities with the default ones, write a custom callback that calls mam_geofilters_list::add_geofilters() (or its public equivalent) and appends to the result.


Verification

This article was last verified against:

  • Plugin: mam-geodirectory v2.1.5
  • Plugin: mam-geofilters v2.1.1
  • Source: mam-geodirectory.phpmam_geofilter_list()

Re-verify whenever the schema of {prefix}{post_type}_detail changes (notably the city, region, latitude, longitude columns), convert_state() adds or removes entries, or mam-geofilters changes how it gates the default-list path.


  • Plugin: mam-geodirectory
  • Content type: GeoDirectory list and map
  • Hook: mam_geodirectory_explcit_listings

Metadata

Field Value
Article type Plugin Overview
Plugin slug mam-geodirectory
Applies to plugin version 2.1.5+
Category Plugin Reference
Audience WordPress admin
Last verified 2026-05-01
Was this article helpful?
Contents

    Need Support?

    Can't find the answer you're looking for? Don't worry we're here to help!