Skip Navigation

[Cerrado] 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.

This topic contains 1 respuesta, has 2 mensajes.

Last updated by Caridad hace 9 años, 6 meses.

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.


El debate ‘[Cerrado] making calculations with fields’ está cerrado y no admite más respuestas.