Return a Calculated Value in a Pods Template

Calculate values from a Pod using multiple fields in the Pod in a Pods Template

If you’re familiar with Pods Templates, you know you can pass a field into a function and let that function do some manipulation and return your manipulated value. But what if you need to do some calculations based on multiple values from the current post? You can’t send multiple parameters, you can only send one field.

So send the ID, {@ID}, of the current post and open a Pods object in your function to do the work and return your value.

function return_current_age( $id ) {
  $pods = pods('case',$id);
  $age = intval($pods->field('age_d'));
  $date_missing = $pods->field('c_date');
  $date = date("Y-m-d");
  $date_diff = intval($date - $date_missing);
  $age_now = intval($age + $date_diff);
  return $age_now;
}

Then you would call that function using this syntax {@ID,return_current_age}

Contributed by Jamie V

Questions