From d36a7f96dcea59aecf1401f204043fe735aedc4a Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Fri, 5 May 2017 13:06:47 -0400 Subject: [PATCH] Added a filter to get the count of a custom field compared to a given value --- setup/frontHooks.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 7029d7b..b15711f 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -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 -- 2.17.1