adding new filter to get all fields and values by entity and uid
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 2 Nov 2017 19:11:50 +0000 (15:11 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 2 Nov 2017 19:11:50 +0000 (15:11 -0400)
adding a filter that can be called in the theme to get all values and fields by
entity id

setup/frontHooks.php

index e0124fd..79cd784 100644 (file)
@@ -126,6 +126,30 @@ add_filter( 'glm-member-db-fields-front-list-query-params', function( $query ){
     }
     return ( !empty( $queryParams ) ? $query . '&'.implode( '&', $queryParams): $query);
 },10, 1);
+
+add_filter('get_glm_custom_fields', function($uid,$entity_id) {
+    global $wpdb;
+    $fieldsTable   = GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields";
+    $dataTable     = GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data";
+
+    $query = "SELECT $dataTable.field_data, $fieldsTable.field_type, $fieldsTable.field_name "
+    . "FROM $dataTable "
+    . "LEFT JOIN $fieldsTable "
+    . "ON $dataTable.field_id = $fieldsTable.id WHERE $dataTable.entity_id = $entity_id;";
+    
+    $result = $this->wpdb->get_results( $query, ARRAY_A );
+    foreach($result as $key=>$value){
+        if ($result[$key]['field_type'] == 'textarea') {
+            $result[$key]['field_data'] = wpautop($result[$key]['field_data']);
+        }
+    }
+    
+//    echo "<pre>AA" . print_r($result) . "ZZ";
+    return $result;
+    },
+    10,
+    2
+);
 add_filter('glm_custom_fields', function($attribute, $id = 0) {
 
     global $wpdb;