Reece Dodds Reece Dodds - 22 days ago 12
PHP Question

increment the result of PHP MySQL query by number

I am currently using the following code in a WordPress site's functions.php file to display a petition signatory counter on the front-end of the website and it's working fine:

// Add shortcode for GravityForms Petition Form counter
function set_gf_petition_counter_num(){
?>
<script>
jQuery(document).ready(function(){
jQuery('#gf_petition_signed_counter span').text('<?php
$summary = RGFormsModel::get_form_counts(1);
echo "".$summary['total']."";
?>');
});
</script>

<?php
}
add_action( 'wp_footer', 'set_gf_petition_counter_num' );


The issue is that the form submissions are counting at zero because I've only just implemented this form after switching the site from Contact Form 7 to GravityForms.

There's already 127 entries from the old CF7 form and none of these are stored in the database.

It replaces the
<span>0</span>
in the body paragraph
id="gf_petition_signed_counter"
with the number returned by using
get_form_counts(1)
to check for the "entries" count in GravityForms (
1
being the form ID).

How can I increment the number of GF subsmissions it returns by 127 so I have the true number of submissions?

Answer Source

You should just be able to increment the total directly after retrieving the number of forms:

$summary = RGFormsModel::get_form_counts(1);
$summary['total'] += 127;
echo "".$summary['total']."";

Hope this helps! :)