Add Zip Code Search

User
geoDirectory plugin add search by zip code in main search bar
Assistant
To add a **search by zip code** feature in the main search bar of the **GeoDirectory** plugin, follow these steps:

### 1. **Enable Location Settings**
Make sure you have enabled location settings in GeoDirectory. You can do this by going to:

**WordPress Dashboard** > **GeoDirectory** > **Settings** > **General** > **Location Manager**:
– Ensure **Post Code** is enabled in the "Address Fields" section.

### 2. **Modify the Search Bar**
To include zip code in the search bar, you'll need to adjust the settings of the main search form:

**WordPress Dashboard** > **GeoDirectory** > **Design** > **Search** > **Search Form**:
– Here, you can add or customize fields to the search bar.
– Add a **Custom Field** for the zip code if it's not already present.

### 3. **Customize the Search Behavior**
If you need to tweak the functionality further, such as ensuring the zip code field is searchable, you can do this via custom code.

Add the following code snippet to your **theme's `functions.php`** file or via a custom plugin:

add_filter('geodir_search_fields', 'gd_add_zipcode_search_field');
function gd_add_zipcode_search_field($search_fields) {
    $search_fields['gd_postcode'] = array(
        'title' => __('Zip Code', 'geodirectory'),
        'type' => 'text',
        'field' => 'gd_postcode',
        'compare' => 'LIKE',
    );
    return $search_fields;
}

### 4. **Update the GeoDirectory Search Template (Optional)**
If the zip code search field is not showing up, you may need to customize the search template file.

– Go to your active theme directory: `/wp-content/themes/your-theme/`
– Locate the `geodirectory/search.php` file. If it doesn't exist, copy it from the GeoDirectory plugin folder: `/wp-content/plugins/geodirectory/templates/search.php`.
– Edit the file and include the zip code search field:

<input type="text" name="s" placeholder="<?php esc_attr_e('Enter zip code', 'geodirectory'); ?>" />

### 5. **Clear Cache & Test**
– Clear your website and browser cache.
– Test the main search bar to ensure it is correctly filtering by zip code.

This approach should allow your GeoDirectory search bar to include and search by zip code effectively.

User
Location manager not found
Assistant
If the **Location Manager** option is not found in the **GeoDirectory** settings, it could mean that you do not have the **GeoDirectory Location Manager** add-on installed. The core GeoDirectory plugin does not include location-specific features like searching by zip code out-of-the-box; this functionality is part of their Location Manager add-on.

### Here's how you can enable and use search by zip code:

#### 1. **Install the GeoDirectory Location Manager Add-On**
You need to install the **Location Manager** add-on to use zip code searches:

– Go to **WordPress Dashboard** > **Plugins** > **Add New**.
– Search for "GeoDirectory Location Manager".
– If you have a license, download the add-on from the [GeoDirectory website](https://wpgeodirectory.com/downloads/location-manager/) and upload it.
– Click **Install Now**, then **Activate**.

#### 2. **Configure Location Manager**
Once installed, configure the settings:

– Go to **WordPress Dashboard** > **GeoDirectory** > **Location Manager**.
– Under the **Address Fields** section, make sure the **Post Code** (Zip Code) field is enabled.
– Save the changes.

#### 3. **Enable Zip Code Search in the Search Form**
You may need to adjust the search form settings:

– Navigate to **WordPress Dashboard** > **GeoDirectory** > **Design** > **Search** > **Search Form**.
– Add a new field for **Zip Code** if it's not already present:
– Choose **Post Code** as the field type.
– Set up the placeholder text, such as "Enter Zip Code".
– Save the changes.

#### 4. **Test the Search Feature**
– Clear any caching if you have a caching plugin enabled.
– Test the search bar on the front end to ensure it accepts zip codes and displays relevant results.

### If You Don't Have the Add-On
If you do not have access to the **Location Manager** add-on, you can use a workaround by adding a custom field for the zip code and modifying your search template. However, the built-in zip code functionality requires the add-on for accurate geolocation-based searches.

Let me know if you need further assistance or a code-based solution for custom fields!

Leave a Comment

Your email address will not be published. Required fields are marked *