Skip Navigation

[Closed] Calculating with field values

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.

This topic contains 1 reply, has 2 voices.

Last updated by Caridad 8 years, 3 months ago.

Assigned support staff: Caridad.

Author
Posts
#16343

Hi, I'd like to calculate percentage % of two values of my Types fields, that are numeric. I'd like the show the result in a View template.
It is a fundraising thing, and I want to calculate and print out to the page how much in % has been raised at the moment.

The fields are like:
[types field="current" format="FIELD_VALUE"]
[types field="goal" format="FIELD_VALUE"]

So I should do the calculation:
percentage = ((current/goal)*100)

Is it possible, and how can I do it?

Thanks a lot in advance, I love your plugins! 🙂

#16380

Dear Harriet,

This functionality is not included in Views, but you can easily create a shortcode that does. First add these lines to functions.php in your theme:

add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts) {
   return wpv_condition($atts);
}

Now you can use this shortcode like this:

[wpv-calculate evaluate=" [types field="current"][/types] / [types field="total"][/types] * 100 "]%

Please let me know if there is anything else that I can assist you with.

Regards.
Caridad

The topic ‘[Closed] Calculating with field values’ is closed to new replies.