Skip Navigation

[Gelöst] Adding Values Together

This support ticket is created vor 5 Jahre, 11 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 Antwort, has 2 Stimmen.

Last updated by Luo Yang vor 5 Jahre, 11 Monate.

Assisted by: Luo Yang.

Author
Artikel
#889912

I have a custom repeater group. In the group is a number field. Now, in the post type I have 4 sets. The number fields are all 5.

I want to have a view that will add all those number fields together and give the result. I cannot figure out how to do this. The view is looping through the fields and outputting in

  • tags. But I need them to combine as one output. I know sometimes you can have the view output with a comma separator. Is there any way to use this to spit out all of my custom field values so I can do some math on them?

    I am using this as an example: https://toolset.com/forums/topic/math-with-custom-fields-values/#post-509325

    Thanks in advance.

  • #891247

    Hello,

    There isn't such a built-in feature within Views plugin, and it needs custom codes, you can try this:
    1) put the custom PHP codes into your theme file functions.php:

    add_shortcode('calculate', function( $atts = [], $content=null ) {
     
        $atts = shortcode_atts([ 'round' => 0 ], $atts );
     
        $content = wpv_do_shortcode($content);
        $content = eval("return $content;");
        return round($content, $atts['round']);
    });
    

    https://toolset.com/forums/topic/math-with-custom-fields-values/#post-509325

    2) Create a view list your custom repeater group, in the section "Loop Editor", use above custom shortcode like this:

    ...
    	<!-- wpv-loop-start -->
    		[calculate round=2]<wpv-loop>[wpv-item index=1][types field="num1"][/types][wpv-item index=other]+[types field="num1"][/types]</wpv-loop>[/calculate]
    	<!-- wpv-loop-end -->
    ...
    

    It will be able to output the results as math calculation.

    More help:
    https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-item
    Used in the loop. Sets a condition to be met for subsequent lines in the loop to be executed.

    This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.