Skip Navigation

[Resolved] Math Calculations with Custom Fields of related posts inside a View

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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 3.64 hours from now. Thank you for your understanding.

This topic contains 1 reply, has 1 voice.

Last updated by Kenneth Horn 5 years, 4 months ago.

Author
Posts
#1291265

I'm using mathematical calculations native to PHP using the plugin code described in this post: https://toolset.com/forums/topic/math-with-custom-fields-values/
I have a View that pulls custom-fields from a related Parent post. The code works fine inside a view calculating fields in the queried post but I'd like to display the product of a custom-field in the loop and a custom-post in the parent post. It doesn't seem to work. I'm using this code:
[calculate round="2"][types field="cup-weight-ing" output="raw"]*[types field="quantity-1" output="raw" item="$post"][/types][/calculate]
I also tried it with this code: [calculate round="2"][types field="cup-weight-ing" output="raw"]*[types field='quantity-1' output='raw' item='@post-and-ingredient.parent'][/types][/calculate]
It only displays the field in the CPT that's queried in the loop.
Is it possible to compute a product pulling variables from both post types?
Thanks

#1291267

My issue is resolved now. I reversed the order of the two fields, used the field "in the page where the view is shown" times the field in the loop and it worked.
Here is the code that worked: [calculate round="2"][types field='quantity-1' item='$current_page'][/types]*[types field="cup-weight-ing" output="raw"][/calculate]
Thanks!