Archived topic
Convert timestamp from custom field type
3 replies · Started by Kim on March 29, 2023
Hi there,
I am trying to create an archive page from a custom content type (Events) that has some custom field types (like: wpcf-date-time-start).
For this I am creating an element as described in https://docs.generatepress.com/article/block-element-content-template/
I managed to get the value from the date-time-start custom field in a Headline block by following this tutorial: https://www.youtube.com/watch?v=Ff7ikQ7Yw0w
But the value is a timestamp like "1680220800". Is there a way I can convert this to a readable date?
I'm not sure if it's relevant but I'm creating custom post types and fields with Toolset.
Also, I have created an archive-event.php template in a child theme.
Hi there,
just had a look at the Toolset Date field:
https://toolset.com/documentation/customizing-sites-using-php/functions/#date
If you expand the + More it has some How to use this field with: Shortcodes including one for a formatted date eg.
[types field="wpcf-date-time-start" format="Y/m/d g:i:s A"][/types]
Try adding shortcode inside a Headline block.
Thansk for your fast reply David!
If I paste the short code in a Headline block it will automatically change into a paragraph block. That's ok I guess, I don't really need it to be a headline.
The shortcode did not work initially but changing it to [types field="date-time-start" format="Y/m/d g:i:s A"][/types] did to thrick. (Removed "wpcf-" from the field value).
Thanks!
Glad to be of help.