From: Laury GvR Date: Fri, 5 May 2017 17:06:47 +0000 (-0400) Subject: Added a filter to get the count of a custom field compared to a given value X-Git-Tag: v1.0.3^2~6 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=d36a7f96dcea59aecf1401f204043fe735aedc4a;p=WP-Plugins%2Fglm-member-db-fields.git Added a filter to get the count of a custom field compared to a given value --- 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