The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Calculate Multiple Totals of Field Results
Since I couldn't figure out how to do this any other way, I thought I would include my method for others to benefit from.
Or perhaps there is a way and I'm just not seeing it.
My need: I needed to not only display totals based on form responses, but also do calculations against those totals.
My issues:
-
You must include a valid field id or key in your stats shortcode.
would only return a count out a single field where the results were "Blah Blah". I was unable to then manipulate that count adding it to other totals, etc. - The new addition of Field Calculations only works inside a form, and I needed to calculate data outside of the forms, in a Page or Post.
My method:
Using WordPress Plugin Shortcode Exec PHP: http://wordpress.org/extend/pl.....-exec-php/
For example, I created the following shortcodes: (291 and 296 are the field IDs.)
[subtotals]
$pending=FrmProFieldsHelper::get_field_stats(296, 'count', $user_id=false, $value='Pending', $round=1);
$edits=FrmProFieldsHelper::get_field_stats(296, 'count', $user_id=false, $value='Edits Needed', $round=1);
$content=$pending+$edits;
print($content);
[petotals]
$pending=FrmProFieldsHelper::get_field_stats(296, 'count', $user_id=false, $value='Pending', $round=1);
$edits=FrmProFieldsHelper::get_field_stats(296, 'count', $user_id=false, $value='Edits Needed', $round=1);
$content=$pending+$edits;
print($content);
[calctotal]
$private=FrmProFieldsHelper::get_field_stats(191, 'count', $user_id=false, $value='Sub Private', $round=1);
$public=FrmProFieldsHelper::get_field_stats(191, 'count', $user_id=false, $value='Sub Public', $round=1);
$pending=FrmProFieldsHelper::get_field_stats(296, 'count', $user_id=false, $value='Pending', $round=1);
$edits=FrmProFieldsHelper::get_field_stats(296, 'count', $user_id=false, $value='Edits Needed', $round=1);
$content=$private+$public-$pending-$edits;
print($content);
Result:
On the page, I can now use:
<h4>There are currently [subtotals] Sub-Private and Sub-Public articles in CTMS, but only [petotals] articles in the Tier I/II Tracking Data that are incomplete. This number should roughly match. This means there are currently [calctotal] articles unaccounted for.</h4>
Which results in, all nicely formatted:
There are currently 76 Sub-Private and Sub-Public articles in CTMS, but only 40 articles in the Tier I/II Tracking Data that are incomplete. This number should roughly match. This means there are currently 36 articles unaccounted for.
Hopefully that is helpful to others.
May 18, 2018 at 12:23 am
Thank you for a great tip! I was getting exactly the same error message and was able to overcome it and complete all my calculations using your suggestion above!
Discussion closed.