Skip Navigation

[Resolved] Calculating

This support ticket is created 2 years, 11 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2243763

Tell us what you are trying to do? I have a projects list with a start date for each project in custom Type. i want to display the average energy savings for each minute for all projects combined. So one project started on May 1, 2021 and had an energy savings of "2" per day and another may be Jan 1, 2019 with a savings of '3". I want to calculate the number of minutes from the start date to current date then multiple it times the savings foor each project, then add them all up for one total. What do you recommend?

Is there any documentation that you are following? No

Is there a similar example that we can see? No

What is the link to your site? hidden link

#2243977

Hello,

There isn't such kind built-in feature, you might consider custom codes, for example:
1) Create a custom shortcode with custom PHP function
https://developer.wordpress.org/reference/functions/add_shortcode/
2) In this custom PHP function, get the timestamp value from custom date field "start date":
https://developer.wordpress.org/reference/functions/get_post_meta/
Calculate the result, and output it as what you want:

One thing need to pay attention, if the custom date field is created with Toolset Types plugin, you need to add prefix "wpcf-" before the field slug, for example, if your custom date field is using slug "my-date-field-slug", you can get it's value like this:

$my_date = get_post_meta(get_the_ID(), 'wpcf-my-date-field-slug', true);

More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/

when you are accessing custom fields through native WordPress functions, you need to prepend the wpcf- prefix to the slug. Continuing from the above example, for native WordPress function to access the “House Price” field, you need to use the wpcf-house-price slug.