sum function


This Discussion is public


i use the follow as its say in the

add_filter('frm_before_display_content', 'dynamic_frm_stats', 10, 4);
function dynamic_frm_stats($content, $display, $show, $atts){
    if ( $display->ID == 1066 ) {//Change 1066 to the ID of your View
        $entries = $atts['entry_ids'];
        $total = 0;
        foreach($entries as $entry){
            $current_value = FrmProEntriesController::get_field_value_shortcode(array( 'field_id' => x, 'entry' => $entry ) );
            if ( $current_value ) {
                $total += $current_value;
        $content = str_replace('[sum_x]', $total, $content);
    return $content;

But what happens if i want to have sum in many vies???
1066 view works perfect, but what if i make a copy of this viw and still want to have sums??

should i make a copy of the above code in the function.php file so many times as many views i have???

Yes. You will have to give each copy a different function name. I find including the view, form, or field id, depending on the function, as a good name.

Example 1:

add_filter('frm_before_display_content', 'dynamic_frm_stats_1320', 10, 4); function dynamic_frm_stats_1320($content, $display, $show, $atts){

Example 2:

add_filter('frm_before_display_content', 'dynamic_frm_stats_1100', 10, 4); function dynamic_frm_stats_1100($content, $display, $show, $atts){


Why not use in_array test :

$view_id = $display->ID

if ( in_array( $view_id , array( 1066, 1100, 1162 ) )  )  {
// Your code ...

or maybe OR operator :

if ( $display->ID == 1066 ||  $display->ID == 1100 || $display->ID == 11162)  {
// Your code ...

I believe in economizing code and would use the in_array method as suggested by Lamiki.This will allow you to use the one small snippet for as many fields as you'd like to sum.

Dear Friends

First of all i  thank you very much

As you can understand I m not a programmer

I m accountant, and i try to make something for our office  a small app

I cannot understand  what is in_aray test, where to write this little code

what is small snippet.

What ever i learn so far i did it by myself. I try hard to understand  some terminology

I have to say thanks to all of you for your help. I already try the method  Mr Bobby Clapp

say, because i can make it.


Hi Guys,

I have a related issues to this snippet that i noticed over the weekend:

It works well for most view types except the Dynamic view. In list mode it all works nicely but when you go to the detail view it produces an error:

Warning: Invalid argument supplied for foreach() in /var/sites/f/ on line 102

As stated in the error message line 102 in my plugin is the start of the foreach($entries as $entry) statement.

I haven't looked into it much yet but thought i'd share the issue for others. I'll post a solution for it soon hopefully (unless anyone else already has a solution for this issue?).



Hi guys,

The solution to the error above was actually nice and simple. See below:

foreach ( (array) $entries as $entry ){
$total += (double) FrmProStatisticsController::stats_shortcode(array('id' => 173, 'type' => 'total', 'entry_id' => $entry) );



Reply to this Discussion