Support » Plugin: GravityWP - Count » Count entries from multiple forms

  • Resolved Schalk Joubert

    (@schalkjoubert)


    Hi,

    I have 2x identical forms with ID:1 and ID:4
    Im trying to count and combine the entries of both forms with something like this…

    [gravitywp_count_star formid=”1,4″ field=”8″ decimals=”2″ dec_point=”.” thousands_sep=”,”]

    Thank you

    Schalk

Viewing 7 replies - 1 through 7 (of 7 total)
  • I managed this by creating another shortcode that count the display value of the two form’s shortcode.

    add_shortcode('mysum','tsum_mysum');
    function tsum_mysum() {
    	$a = do_shortcode('[gravitywp_count_star formid="1" field="8"  decimals="2" dec_point="." thousands_sep=","]');
    	$b = do_shortcode('[gravitywp_count_star formid="11" field="8"  decimals="2" dec_point="." thousands_sep=","]');
        $c = $a + $b;
    return " <div>The sum is <strong>".$c."</strong></div>";      
           }
    Plugin Author GravityWP

    (@gravitywp)

    Hi Schalk,

    Thank you for sharing. I think that’s an excellent solution. You could also pass atts in your shortcode to make the sum shortcode even more flexible.

    Kind regards,
    Erik

    Using the method mentioned by @schalkjoubert is there a way to count entries of all forms without manually entering the id?

    • This reply was modified 1 year, 1 month ago by  fcvolunteer.
    Plugin Author GravityWP

    (@gravitywp)

    Hi @fcvolunteer,

    If you don’t use the number field and leave the form id empty, it will show the total number of entries.

    If you want to automatically count all the number fields for all the entries of all forms, you’ll need another script. Since the number field you want to count will most probably differ per individual form, I think the solution is too much. I think you should look at making something that looks for a specific css code or something.

    Thanks! That was exactly what I needed!

    hi all

    Will Schalk’s solution work for the current user ?

    I need to insert code into the user profile template that will output a count of their total entries across two forms: ID 1 and ID 8, between two dates

    thanks a lot

    joe

    it does work for current user

    I used this

    ‘add_shortcode(‘mysum’,’tsum_mysum’);
    function tsum_mysum() {
    $a = do_shortcode(“[gravitywp_count formid=’1′ start_date=’01/01/2018′ end_date=’12/31/2018′ created_by=’current’]”);
    $b = do_shortcode(“[gravitywp_count formid=’8′ start_date=’01/01/2018′ end_date=’12/31/2018′ created_by=’current’]”);
    $c = $a + $b;

    if ($c <20) { return “Friend”; }
    if ($c >19 && $c<40) { return “Family”; }
    if ($c >39) { return “Soulmate”; }

    }’

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Count entries from multiple forms’ is closed to new replies.