Skip Navigation

[Résolu] Calculate two fields from different Post types

This support ticket is created Il y a 8 années. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Marqué : 

This topic contains 3 réponses, has 2 voix.

Last updated by Minesh Il y a 8 années.

Assisted by: Minesh.

Auteur
Publications
#380797

I can calculate two fields from the same post types using the method explained here:

add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts,$content=null) {
$content = wpv_do_shortcode($content);
$content = eval("return $content;");
return round($content);
}

However I need to calculate two fields from different Post Types. For example

I have Post type houses that contain a price and i have another Post Type called Lots which have a price as well. Houses are a child of Lots because any type of house can be built on a Lot.

I need to create a view that show the total price of them both combined. How do i achieve this?

#380909

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know have you created parent/child relationship using types?

With which content type [houses, lots] you are creating your view?

#381108

Yes everything is completed using types/views including parent/child relationships.

For the views I created a Main View for Lots(Parent) and then have a view within the Lots View for the child posts of houses.

To do the calculations I use:

[types field="House-Price"][/types] + [types field="Lot-Price"][/types]

#381128

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

To get the parent post field value you need to add id="$parent_posttype_slug" attribute to yor types field.

For example:

[types field="House-Price"][/types] + [types field="Lot-Price" id="$lots"][/types]

Could you please try above line and try to resolve your issue.

More info:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.