Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Last active August 28, 2019 04:34
Show Gist options
  • Save rafaehlers/85638ed8179984aa833b1b14a1b68e7c to your computer and use it in GitHub Desktop.
Save rafaehlers/85638ed8179984aa833b1b14a1b68e7c to your computer and use it in GitHub Desktop.
Display a progress bar using the Math extension
<?php // DO NOT COPY THIS LINE
// usage inside a Custom Content field on a View: [gv_math_percentage field="{field Merge tag here:x}"]
add_shortcode("gv_math_percentage", "gv_math_custom_shortcode");
function gv_math_custom_shortcode( $atts ){
extract( shortcode_atts(
array(
'field' => '',
), $atts )
);
$value = do_shortcode('[gv_math scope="entry"] ('.$field.' / 34 ) * 100[/gv_math]');
$text = '<progress value='.$value.' max="100"></progress>';
return $text;
}
add_filter( 'gravityview/math/suppress_errors', '__return_true' ); // this is needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment