From 68ab46867fc002d5252b3773ba261438a50e897e Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Fri, 28 Apr 2017 10:56:26 -0400 Subject: [PATCH] adding search functionality to the header search widget added form field names and modified the search query filter in the functions php file to handle the counties and cities as well as the regions. the categories were used in place of the manufacturers from brewbakers --- functions.php | 59 +++++++++++++++++++++++++-------------------- sections/header.php | 12 ++++----- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/functions.php b/functions.php index fc3ecbc..e78962e 100644 --- a/functions.php +++ b/functions.php @@ -20,32 +20,39 @@ if (!function_exists('glm_quicksite_widget_init')) { } } -//add_filter('glm-member-db-front-search-query', function( $queryParts ) { -// //$queryParts = array(); -// if ( isset( $_REQUEST['manufacturers'] ) && is_array( $_REQUEST['manufacturers'] ) && !empty( $_REQUEST['manufacturers'] ) ) { -// $catSelectedForQuery = implode( ',', $_REQUEST['manufacturers'] ); -// $queryParts[] = " T.id in ( -// SELECT DISTINCT(member_info) -// FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M, -// ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C -// WHERE M.category in($catSelectedForQuery) -// OR (C.parent in($catSelectedForQuery) AND M.category = C.id) -// ) "; -// } -// // Check to see if Pre-Owned is not set. If it is not set then only get -// // listings without the Pre-Owned -// if ( !isset( $_REQUEST['pre_owned'] ) ) { -// $queryParts[] = " T.id IN ( -// SELECT ref_dest -// FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data -// WHERE field_data != 'Yes' -// AND field_id = (SELECT id -// FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields -// WHERE field_name = 'Pre-Owned') -// ) "; -// } -// return $queryParts; -//}); +add_filter('glm-member-db-front-search-query', function( $queryParts ) { + //$queryParts = array(); + if ( isset( $_REQUEST['categories'] ) && is_array( $_REQUEST['categories'] ) && !empty( $_REQUEST['categories'] ) ) { + + $catSelectedForQuery = implode( ',',array_filter( $_REQUEST['categories'] )); + $queryParts[] = " T.id in ( + SELECT DISTINCT(member_info) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C + WHERE M.category in($catSelectedForQuery) + OR (C.parent in($catSelectedForQuery) AND M.category = C.id) + ) "; + } + if ( isset( $_REQUEST['cities'] ) && is_array( $_REQUEST['cities'] ) && !empty( $_REQUEST['cities'] ) && $_REQUEST['cities'][0] !== '' ) { + + $catSelectedForQuery = implode( ',',array_filter( $_REQUEST['cities'] )); + $queryParts[] = " T.id in ( + SELECT DISTINCT(member) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info M + WHERE M.city = $catSelectedForQuery + ) "; + } + if ( isset( $_REQUEST['counties'] ) && is_array( $_REQUEST['counties'] ) && !empty( $_REQUEST['counties'] ) && $_REQUEST['counties'][0] !== '' ) { + print_r($_REQUEST['counties']); + $catSelectedForQuery = implode( ',',array_filter( $_REQUEST['counties'] )); + $queryParts[] = " T.id in ( + SELECT DISTINCT(member) + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info M + WHERE M.county = $catSelectedForQuery + ) "; + } + return $queryParts; +}); /** * Return the client info option for the given key * diff --git a/sections/header.php b/sections/header.php index 11c7792..7a2051b 100644 --- a/sections/header.php +++ b/sections/header.php @@ -38,21 +38,21 @@
?action='list'"> Search by Location - - - @@ -62,19 +62,19 @@
Search by - - - -- 2.17.1