Added a filter to get the count of a custom field compared to a given value
authorLaury GvR <laury@gaslightmedia.com>
Fri, 5 May 2017 17:06:47 +0000 (13:06 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 5 May 2017 17:06:47 +0000 (13:06 -0400)
setup/frontHooks.php

index 7029d7b..b15711f 100644 (file)
@@ -128,3 +128,23 @@ add_filter('glm_custom_fields_member_types', function() {
     10,
     2
 );
+
+/**
+ * Filter: glm-get-custom-field-count
+ * Usage: apply_filters( 'glm-get-custom-field-count','reviewed','Yes' )
+ */
+add_filter( 'glm-get-custom-field-count', function( $field_name, $field_value = '' ){
+    if ( $field_name ) {
+        global $wpdb;
+        $sql = "SELECT count(field_data) FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data WHERE field_data LIKE '$field_value'"
+                . " AND field_id IN (SELECT id FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields WHERE field_name LIKE '$field_name')";
+        $count = $wpdb->get_var(
+            $sql
+        );
+        return $count;
+    }
+    return false;
+},
+10,
+2
+);
\ No newline at end of file