Skip Navigation

[Closed] making calculations with fields

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.

Our next available supporter will start replying to tickets in about 5.69 hours from now. Thank you for your understanding.

This topic contains 1 reply, has 2 voices.

Last updated by Caridad 9 years, 5 months ago.

Assigned support staff: Caridad.


Is it possible to make a calculation with fields?

What I want to do is this:
I have a field in a custom post type named "price per week"
I want to make a view/template with a table where in one cell this "price per week" field is shown and in the next cell I want to display automatically the value of 20% of "price per week"

If possible, how would I do this?



Dear Jeroen,

It is not possible to do calculations with Views, but you can always create a shortcode to help you achieve it. Try adding these lines to functions.php in your theme:

add_shortcode('wpv-calculate', 'wpv_calculate_shortcode');
function wpv_calculate_shortcode($atts) {
 global $post;
 foreach ($atts as $key => $value) {
  if (substr($value,0,5) == 'wpcf-') {
   $$key = get_post_meta($post->ID, $value, true);
 $out = false;
 eval("\$out = $atts[expression];");
 return $out;

Now you can make calculations with custom fields like this:

Total price: [wpv-calculate f1="wpcf-price" expression="$f1 * 1.20"]

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


The topic ‘[Closed] making calculations with fields’ is closed to new replies.