Calculating a person's age based on a date field
Ever wanted to calculate someone else's age based on a date field? That's possible using the [gv_age]
shortcode.
Shortcode Parameters
The [gv_age]
shortcode requires two parameters to calculate age.
entry_id
- The ID of the entry for the age calculation. Can use the{entry_id}
Merge Tag or a numeric entry ID.field_id
- The ID of the date field where date of birth is stored.
Example
This shortcode will calculate ages for all entries. Date of birth is stored in a date field with an ID of 44:
[gv_age entry_id="{entry_id}" field_id="44" /]
Adding the [gv_age]
shortcode to a Custom Content field:
The output:
Now that we have the age displaying, we can enter a label for the Custom Content field:
And voilá:
You'll need this code in order to enable the [gv_age]
shortcode: