modifiying the search filter in the functions file to make the query for categories
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 1 May 2017 12:45:34 +0000 (08:45 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 1 May 2017 12:45:34 +0000 (08:45 -0400)
an AND instead of OR

looping through the categories to append a query clause for categories to make it search
for AND instead of OR for each header search category option. The glm-member-db-front-search-query
is where the changes were made

functions.php

index f98bcac..7db25d2 100644 (file)
@@ -24,14 +24,18 @@ 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 (
+//        $catSelectedForQuery = implode( ',',array_filter( $_REQUEST['categories'] ));
+        foreach( $_REQUEST['categories'] as $cat ){
+            if( $cat !== ''){
+                $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) 
+                     WHERE M.category = $cat
     
-            ) ";
+                ) ";
+            }
+        }
     }
      if ( isset( $_REQUEST['cities'] ) && is_array( $_REQUEST['cities'] ) && !empty( $_REQUEST['cities'] ) && $_REQUEST['cities'][0] !== '' ) {