WP Manifestindependent plugin directory
manifest / utilities / multi-location-vars

Multi Location Vars

Using Custom Post Types and Advaced Custom Fields to pass data to local sites

by Casey Boone · github.com/caseyrboone/multi-location-vars

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/caseyrboone/multi-location-vars/archive/refs/heads/main.zip

Multi Location Vars (WordPress Plugin)

A lightweight WordPress plugin that lets you manage location‑specific variables (address, phone, social links, hours, etc.) as a custom post type and output them anywhere via a single shortcode. The active location can be resolved from either a cookie or the first URL path segment, with a configurable default fallback.


Key Features

  • Custom Post Type: multi_location_vars with common business fields (address, phone, socials, hours, etc.).
  • Shortcode: [multi_location_vars] to print a specific field for the current location.
  • Location resolution:
    • Cookie: STYXKEY_qv_location (common on WP Engine) if enabled.
    • URL: first path segment (e.g., /atlanta/...) if cookie mode is off.
    • Default fallback: use a sitewide default location if neither cookie nor URL matches.
  • Admin settings page to choose cookie vs. URL mode and set the default location.
  • Works in posts, pages, widgets, and templates (do_shortcode).

Requirements

  • WordPress 5.0+
  • PHP 7.4+ (8.x compatible in typical setups)
  • (Bundled) ACF v4 library for legacy fields in lib/acf/

Note: ACF is bundled for historical reasons. For modern projects, you can replace it with your own ACF installation if desired.


Installation

  1. Copy the plugin folder multi-location-vars/ into wp-content/plugins/.
  2. Activate Multi Location Vars from Plugins in wp‑admin.
  3. In Settings → Multi Location Vars Config:
    • Choose Cookie or URL mode for location resolution.
    • Set a Default Location (used as a fallback).

Creating Locations

  1. Go to Multi Location Vars in the admin menu.
  2. Add New and fill in the fields (see field keys below).
  3. The Location field should match how you identify the location:
    • URL mode: set it to the first path segment (e.g., atlanta for https://example.com/atlanta/).
    • Cookie mode: set a cookie named STYXKEY_qv_location with the same value (e.g., atlanta).

Usage

Shortcode (in content)

[multi_location_vars id="phone_number"]
[multi_location_vars id="address_1"]
[multi_location_vars id="store_hours"]

In PHP templates

echo do_shortcode('[multi_location_vars id="phone_number"]');

Setting the cookie (example)

// Set cookie for 7 days (adjust as needed)
document.cookie = "STYXKEY_qv_location=atlanta; path=/; max-age=" + 60*60*24*7;

The plugin will resolve the current location by cookie (if enabled), else by URL segment, else by the configured default location.


Field Keys (for id attribute)

Use these keys with the shortcode or in code. Examples:

  • Locationlocation
  • Phone Numberphone_number
  • Formal Business Namebusiness_name
  • Address 1address_1
  • Address 2address_2
  • Citycity_1
  • Statestate_1
  • Zip codezip_1
  • Facebook URLfacebook
  • Twitter URLtwitter
  • LinkedIn URLlinkedin
  • Youtube URLyoutube
  • Pinterest URLpintrest
  • Instagram URLinstagram
  • Yelp URLyelp
  • Location Site Name & custom yoast variable valuelocation_custom
  • Emailemail
  • FPC Location Namefpc_location_name
  • FPC Groupfpc_group
  • FPC Auto Responder IDfpc_responder
  • FPC Account API Keyfpc_api_key
  • Calendar Typecalendar_type
  • Fit Pro Tracker URLfit_pro_tracker_url
  • Calendar API Keycal_api_key
  • Territoryterritory
  • Google Map URL (only if dynamic map is not working)additional_field
  • Latitudeadditional_field_2
  • Longitudeadditional_field_3
  • Service Area City 1additional_field_4
  • Store Hoursstore_hours
  • Service Area City 2custom_text_2
  • Service Area City 3custom_text_3
  • Wiki City linkcustom_text_4
  • Additional text field 5custom_text_5
  • Current Promocurrent_promo
  • Fit Body Forever AR IDforever_ar_id
  • Multi Location FBmulti_location_fb
  • Fbbc FBfbbc_fb
  • Fbbc FB1fbbc_fb1
  • Grand Opengrandopen

You can add more fields via ACF as needed. Keep the field name (not the label) consistent when using the shortcode id.


Admin & Settings

  • Settings page (Settings → Multi Location Vars Config):
    • Toggle Cookie vs URL mode.
    • Set the Default Location (post ID used when nothing else matches).
  • List Table Enhancements: Custom columns for quick scanning of locations.

Developer Notes

  • Helper used internally: get_post_id_by_meta_key_and_value( $key, $value ) for resolving a location by its meta (defaults to location key).
  • The shortcode ultimately calls ACF’s get_field( $field_key, $location_post_id ).
  • If you don’t use WP Engine, you may still set the same cookie name (STYXKEY_qv_location) or adapt the code to a different cookie name.

Folder Structure

multi-location-vars/
├─ multi-location-vars.php          # Main plugin bootstrap
├─ lib/
│  ├─ cpt/multi_location_vars.php   # CPT + ACF field registrations
│  └─ acf/                          # Bundled ACF v4 (legacy)
└─ README.md                        # This file

Changelog

  • 1.2 – Stable internal release; settings page; shortcode; cookie/URL resolver; default fallback.

Contributing

  1. Fork the repo and create a feature branch.
  2. Keep changes focused and documented.
  3. Open a PR with a clear description and testing notes.