Skip Navigation

[Resolved] Calculate age

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display calculated age from custom field from view having filter by current post

Solution:
You should set your view to filter by the post ID using shortcode attribute and pass the current post ID as shortcode attribute value.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/calculate-age/#post-917978

Relevant Documentation:

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

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)

This topic contains 7 replies, has 2 voices.

Last updated by Bob 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#917874

Bob

I'm trying to make the script from this topic work:
https://toolset.com/forums/topic/calculte-age/

I have a CPF with June 26, 1998 set in the date field. Following the steps as described in the above link I get "20 48 49 146" as an outcome.

What am I doing wrong here?

#917876

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I would like to know, is the date field is created using Types plugin? If yes - it should work.

if you can share problem URL and access details - I can better explain you the reason.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#917899

Minesh
Supporter

Languages: English (English )

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

thanks for access details but could you please share problem URL where exactly you want to display the calculated age?

#917900

Bob

sorry about that... just made an edit to the private message 🙂

#917913

Minesh
Supporter

Languages: English (English )

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

Ok - i see now why its displaying "20 48 49 146" - I see you are using view to display the age.
=> hidden link

Now, its loop through all the posts of post type "Gastouders" as view is set to display the content from that post type. Are you wish to display the age from the current post you are displaying?

#917966

Bob

yes, that's the idea 🙂

#917978

Minesh
Supporter

Languages: English (English )

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

Ok - I've added the post ID filter to your view:

  Post ID filter
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]

And I called the view as given under:

Leeftijd {!{wpv-view name="pp-leeftijd-go" ids="{!{wpv-post-id}!}" cached="off"}!} jaar

I can see its displaying now one result and 20 as output.

#918066

Bob

That did the trick Minesh! Thanks a lot 🙂

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