From 481d0a2189da24c4350eb1e45cfab4b0ae79156f Mon Sep 17 00:00:00 2001 From: Justin Hayes Date: Thu, 3 Oct 2024 12:29:31 -0400 Subject: [PATCH] Fix: address search --- CHANGELOG.md | 6 +++++ bridge-directory/README.txt | 2 +- bridge-directory/bridge-directory.php | 2 +- bridge-directory/includes/Search_Handler.php | 26 +++++++++++--------- bridge-directory/package.json | 2 +- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d058b3b..b7e9b87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.2.8] + +### Fixed + +- **Search by address**: Fixed an issue where searching by address was not working as expected. + ## [0.2.7] ### Fixed diff --git a/bridge-directory/README.txt b/bridge-directory/README.txt index 827c788..0c66485 100644 --- a/bridge-directory/README.txt +++ b/bridge-directory/README.txt @@ -3,7 +3,7 @@ Contributors: justinh-rahb Tags: real estate, bridge, brokerage, api Requires at least: 5.0 Tested up to: 6.6.2 -Stable tag: 0.2.7 +Stable tag: 0.2.8 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html diff --git a/bridge-directory/bridge-directory.php b/bridge-directory/bridge-directory.php index 2f8832a..9f8135b 100644 --- a/bridge-directory/bridge-directory.php +++ b/bridge-directory/bridge-directory.php @@ -3,7 +3,7 @@ * Plugin Name: Bridge API Directory * Plugin URI: https://github.com/RAHB-REALTORS-Association/Bridge-Directory-WP * Description: Displays a searchable directory of offices using the Bridge Interactive API. - * Version: 0.2.7 + * Version: 0.2.8 * Author: Cornerstone Association of REALTORS * Author URI: https://www.cornerstone.inc * License: GPL-2.0 diff --git a/bridge-directory/includes/Search_Handler.php b/bridge-directory/includes/Search_Handler.php index ad537b6..739fb8d 100644 --- a/bridge-directory/includes/Search_Handler.php +++ b/bridge-directory/includes/Search_Handler.php @@ -38,14 +38,12 @@ public function search_offices( $query = '', $page = 1, $limit = 20 ) { $parameters[] = $normalized_like_query; } - // Check if the query contains at least one digit for address search - if ( preg_match( '/\d/', $query ) ) { - $where_clauses[] = "(OfficeAddress1 LIKE %s OR OfficeAddress2 LIKE %s OR OfficeCity LIKE %s OR OfficePostalCode LIKE %s)"; - $parameters[] = $like_query; - $parameters[] = $like_query; - $parameters[] = $like_query; - $parameters[] = $like_query; - } + // Remove the digit check to allow address searches without digits + $where_clauses[] = "(OfficeAddress1 LIKE %s OR OfficeAddress2 LIKE %s OR OfficeCity LIKE %s OR OfficePostalCode LIKE %s)"; + $parameters[] = $like_query; + $parameters[] = $like_query; + $parameters[] = $like_query; + $parameters[] = $like_query; } if ( ! empty( $where_clauses ) ) { @@ -53,11 +51,17 @@ public function search_offices( $query = '', $page = 1, $limit = 20 ) { } $sql .= ' ORDER BY OfficeName ASC'; - $sql .= $wpdb->prepare( ' LIMIT %d OFFSET %d', $limit, $offset ); + $sql .= ' LIMIT %d OFFSET %d'; + $parameters[] = (int) $limit; + $parameters[] = (int) $offset; + + // Prepare the entire SQL statement with all parameters at once + $prepared_sql = $wpdb->prepare( $sql, $parameters ); - $sql = $wpdb->prepare( $sql, $parameters ); + // Optional: Log the final SQL for debugging + // error_log( $prepared_sql ); - $results = $wpdb->get_results( $sql, ARRAY_A ); + $results = $wpdb->get_results( $prepared_sql, ARRAY_A ); return $results; } } diff --git a/bridge-directory/package.json b/bridge-directory/package.json index 98dc0f7..2d1c77a 100644 --- a/bridge-directory/package.json +++ b/bridge-directory/package.json @@ -1,6 +1,6 @@ { "name": "bridge-directory", - "version": "0.2.7", + "version": "0.2.8", "description": "A WordPress plugin that displays a searchable directory of offices using the Bridge Interactive API.", "main": "index.js", "scripts": {