Tell us what you are trying to do?
I need to calculate the sum of a set of fields from a series of related posts. Here's a simple breakdown of the challenge:
The page (hidden link) displays a view ("Account Summary by Year") that queries the custom post type Aid Requests, filtering them to show only the Aid Requests that match a particular year and Aid Account (filtered by the query string).
For each resulting Aid Request, I need to calculate the amount of that request. This is tricky because each Aid Request is composed of a set of Aid Items (related post types, one Aid Request to many Aid Items). Each Aid Item has a quantity and cost.
So in plain English, the formula for calculating the amount of each Aid Request would look like this:
1) For each Aid Request, find the related Aid Items.
2) Loop through each of those Aid Items, and multiply the cost times the quantity for the total cost.
3) Add up the total cost of all of the Aid Items
I believe I probably need to achieve this via a custom function, but am not sure how to go about it.
Is there any documentation that you are following?
Is there a similar example that we can see?
No, but Minesh helped me solve a related problem in calculating the sum for a single Aid Request. Here's an example of the end product of that work: hidden link The Requested Items are in a view named List Aid Items for Current Aid Request. The view uses Settings > Custom Code "calculate_sum" which does this task for the Aid Items belonging to a single Aid Request.
The difference with this request is that I need it to loop through and calculate for a whole series of Aid Requests.
In case the above is not clear, I'm attaching two screenshots. The first is from my work-in-progress, with the part I'm needing to calculate highlighted in yellow. The second is from the legacy app we're rebuilding with Toolset, and that one shows what the calculated amounts should be.
What is the link to your site?
hidden link
(By the way, Minesh should still have access to WordPress for this site, as I haven't changed the login info after our last support request).
Thanks!
David