Format the date and time from custom meta fields
-
Hi
I’m not sure if this question would be better on Advanced Custom Fields forum, but it was not possible to register on their forum due to some spam protection. At the same time the issue doesn’t seem to be ACF so I’m reaching out here.I’m using two ACF custom fields: a date picker and a time picker. This has been working well in the past, however now I’m rebuilding my site with WordPress Full site editing, and using paragraph blocks to bind the date and time. To get the custom fields to show on the page I did the following PHP snippet. The one below is for date, but I have a similar for time as well.
register_meta(
'post',
'start_date',
array(
'object_subtype' => 'event',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'sanitize_callback' => 'wp_strip_all_tags'
)
);And this snippet on the page itself and a similar one for time. It’s inside a paragraph block, but didn’t work to post the whole snippet here.
{"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"start_date"}}}}}
It’s all working as it should, however the date format looks like this:
20240715
And the time format:
19:00:00
Is there anyway I can change the date and time format? It doesn’t help to change it within ACF.
Thanks in advance!
- You must be logged in to reply to this topic.