0

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?

2
  • Can't you just do $summary['total'] += 127? Commented Sep 25, 2017 at 3:20
  • Thanks. I had to enclose it in brackets, but it is working. Can you change the comment to an answer to I can accept it as correct. Commented Sep 25, 2017 at 3:30

1 Answer 1

1

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! :)

Sign up to request clarification or add additional context in comments.

1 Comment

I actually implemented by using echo "".($summary['total'] += 127)."";. Is there any downside to doing it this way instead of your suggestion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.