From 3ab07753136568edc6b62f34060054c98552e4be Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 10 Apr 2017 16:28:37 -0400 Subject: [PATCH] Update the filter for custom fields query. Setting up the custom fields query. This will look for the request variable for each custom field and put it into the query if found in the request array. --- setup/frontHooks.php | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/setup/frontHooks.php b/setup/frontHooks.php index cec957b..9f7f68e 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -33,7 +33,7 @@ add_filter('glm-member-db-front-members-detail-sidebar', function($content, $id) 10, 2 ); - add_filter('glm-member-db-front-members-list-info', function($content, $id) { +add_filter('glm-member-db-front-members-list-info', function($content, $id) { $fieldData = do_shortcode('[glm-members-fields-list member='.$id.', template="detail-sidemenu" order="title"]'); $content .= $fieldData; return $content; @@ -41,16 +41,40 @@ add_filter('glm-member-db-front-members-detail-sidebar', function($content, $id) 10, 2 ); -add_filter('glm-member-db-front-search-query', function($query) { - // Look for the member type +add_filter('glm-member-db-front-search-query', function($queryParts) { + echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + // Get all custom fields + $customFields = $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields", + ARRAY_A + ); + if ( isset( $customFields ) && count( $customFields ) > 0 ) { + foreach ( $customFields as $key => $field ) { + switch ( $field['field_type'] ) { + case 'text': + case 'textarea': - //echo '
$query: ' . print_r( $query, true ) . '
'; - //$query .= " AND T.member IN (SELECT id from " . GLM_MEMBERS_PLUGIN_DB_PREFIX. "members WHERE member_type = 3 ) "; - //$query .= " AND T.member IN (SELECT id from " . GLM_MEMBERS_PLUGIN_DB_PREFIX. "members WHERE member_type = 2 ) "; - return $query; + break; + case 'checkbox': + // convert name to lower case and replace spaces with _ + $field_name = str_replace( ' ', '_', strtolower( $field['field_name'] ) ); + if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_VALIDATE_BOOLEAN ) ) { + $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'] ) . "') + ) "; + } + break; + } + } + } + return $queryParts; }); add_filter('glm_custom_fields', function($attribute, $id) { - + global $wpdb; $query = "SELECT field_data FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data WHERE ref_dest = $id " . "AND field_id IN (SELECT id FROM ".GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."custom_fields WHERE field_name LIKE '$attribute' )"; @@ -59,4 +83,4 @@ add_filter('glm_custom_fields', function($attribute, $id) { }, 10, 2 -); \ No newline at end of file +); -- 2.17.1