Skip to content

Instantly share code, notes, and snippets.

@danbru1989
Created February 7, 2026 20:14
Show Gist options
  • Select an option

  • Save danbru1989/38986ffbcd3ba698322371250811e331 to your computer and use it in GitHub Desktop.

Select an option

Save danbru1989/38986ffbcd3ba698322371250811e331 to your computer and use it in GitHub Desktop.
Modify GF Progress Meter
/**
* Gravity Wiz // Gravity Forms // Filter Progress Meter by Field Value
* https://gravitywiz.com/gravity-forms-progress-meter/
*
* Adds support to get the count of entries with a specific values within a specific date range.
*
* Instructions
*
* 1. Install and activate the Progress Meter snippet.
* https://gravitywiz.com/gravity-forms-progress-meter/
*
* 2. Add the following code snippet to your theme's functions.php file or wherever you include custom code.
*
* 3. Follow the inline instructions in the snippet to configure for your form and fields.
*
* 4. Update your progress meter shortcode to include a name attribute with the value "my_custom_filter" (or whatever
* name you've set in the snippet below).
*
* [gravityforms id="123" action="meter" goal="10" name="my_custom_filter"]
*/
add_filter( 'shortcode_atts_gf_progress_meter', function ( $atts ) {
// Update "bem_project_meter" to your desired name to avoid conflicts with other progress meter shortcodes.
if ( $atts['name'] !== 'bem_project_meter' ) {
return $atts;
}
$project_id = 0;
if ( ! empty( $atts['project_id'] ) ) {
$project_id = absint( $atts['project_id'] );
} elseif ( is_singular( 'project' ) ) {
$project_id = get_the_ID();
}
$field_filters = array(
'mode' => 'all',
array(
'key' => 9, // Update to the field ID in which you will search for the value.
'value' => $project_id, // Update to the value you want to search for.
),
);
$search_criteria = array(
'status' => 'active',
);
if ( isset( $field_filters ) ) {
$search_criteria['field_filters'] = $field_filters;
}
// Fetch matching entries
$entries = GFAPI::get_entries( $atts['id'], $search_criteria );
// Sum the field values
$sum = 0;
foreach ( $entries as $entry ) {
$value = GFCommon::to_number( rgar( $entry, $atts['field'] ) );
if ( is_numeric( $value ) ) {
$sum += floatval( $value );
}
}
$atts['count'] = $sum; // This sets the current progress (sum)
return $atts;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment