Adding filter to create the get parameters for custom fields.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Apr 2017 20:11:26 +0000 (16:11 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Apr 2017 20:11:26 +0000 (16:11 -0400)
This will be used in the member list or grid when it builds the Alpha or
the Previous Next page links.

setup/frontHooks.php

index 5780748..557bcbc 100644 (file)
@@ -116,6 +116,26 @@ add_filter('glm-member-db-front-search-query-orderby', function($originalOrderBy
     $orderBy .= ", $originalOrderBy DESC ";
     return $orderBy;
 });
+add_filter('glm-member-db-fields-front-list-query-params', function(){
+    $queryParams = array();
+    // Get all custom fields
+    $customFields = $this->wpdb->get_results(
+        "SELECT field_name,field_type
+           FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX .  "custom_fields",
+        ARRAY_A
+    );
+    foreach ( $customFields as $field ) {
+        switch ( $field['field_type'] ) {
+        case 'checkbox':
+            $fieldName = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
+            if ( isset( $_REQUEST[$fieldName] ) ) {
+                $queryParams[] = "$fieldName={$_REQUEST[$fieldName]}";
+            }
+            break;
+        }
+    }
+    return ( !empty( $queryParams ) ? '&'.implode( '&', $queryParams): '');
+});
 add_filter('glm_custom_fields', function($attribute, $id = 0) {
 
     global $wpdb;