Skip to content

Commit

Permalink
Fix: address search
Browse files Browse the repository at this point in the history
  • Loading branch information
justinh-rahb committed Oct 3, 2024
1 parent 126bb14 commit 481d0a2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion bridge-directory/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bridge-directory/bridge-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions bridge-directory/includes/Search_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,30 @@ 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 ) ) {
$sql .= ' WHERE ' . implode( ' OR ', $where_clauses );
}

$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;
}
}
2 changes: 1 addition & 1 deletion bridge-directory/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 481d0a2

Please sign in to comment.