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>";
}
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 7 years, 10 months ago by
fcvolunteer.
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”; }
}’