From 19feac96fccf4ebf85576a55f680d25b3f723fb0 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 13 Apr 2017 13:11:19 -0400 Subject: [PATCH] Updating search for default non pre-owned rvs. If there's no pre-owned search flag then only get the new rvs. --- setup/frontHooks.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/setup/frontHooks.php b/setup/frontHooks.php index e2065c3..5780748 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -61,17 +61,31 @@ add_filter('glm-member-db-front-search-query', function() { // convert name to lower case and replace spaces with _ $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) ); if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_VALIDATE_BOOLEAN ) ) { - $queryParts[] = " T.id in ( + $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 = '" . esc_sql( $field['field_name'] ) . "') + AND field_id = (SELECT id + FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields + WHERE field_name = '" . esc_sql( $field['field_name'] ) . "') ) "; } break; } } } + // 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-orderby', function($originalOrderBy){ -- 2.17.1