Moving these filters from the fields plugin.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 26 Apr 2017 17:38:14 +0000 (13:38 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 26 Apr 2017 17:38:14 +0000 (13:38 -0400)
They belong in the theme so they are for only brewbakers.

functions.php

index b5747a3..e4a8056 100644 (file)
@@ -39,9 +39,48 @@ add_filter('glm-member-db-front-search-query', function( $queryParts ) {
                         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-orderby', function($originalOrderBy){
+    // Order by clause for Just Arrived.
+    $orderBy = " (
+    SELECT CASE WHEN field_data = 'Yes' THEN 0 ELSE 1 end
+      FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
+     WHERE field_id = (SELECT id
+                         FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+                        WHERE field_name = 'Just Arrived')
+                          AND ref_dest = T.id) ";
+    // Order by clause for Red Hot Deal.
+    $orderBy .= ", (
+    SELECT CASE WHEN field_data = 'Yes' THEN 0 ELSE 1 end
+      FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
+     WHERE field_id = (SELECT id
+                         FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+                        WHERE field_name = 'Red Hot Deal')
+                          AND ref_dest = T.id) ";
+    // Order by clause for Coming Soon.
+    $orderBy .= ", (
+    SELECT CASE WHEN field_data = 'Yes' THEN 0 ELSE 1 end
+      FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
+     WHERE field_id = (SELECT id
+                         FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+                        WHERE field_name = 'Coming Soon')
+                          AND ref_dest = T.id) ";
+    $orderBy .= ", $originalOrderBy DESC ";
+    return $orderBy;
+});
 add_filter('glm_blocks', function() {
     if(function_exists('fetch_all_glm_blocks')) {
         $blocks = fetch_all_glm_blocks();
@@ -55,7 +94,7 @@ add_filter('glm_block_image', function($id) {
     echo get_the_post_thumbnail($id, 'glm-block-image');
 });
 add_filter('get_form_permalink', function($id) {
-    echo get_permalink($id); 
+    echo get_permalink($id);
 });