Split date/time to custom fields
-
Hello,
I am pretty newbie in WordPress and PHP, please could you give me an advice how to solve this issue?I use date and time picker for event start/end. Then I use Elementor dynamic tags to display it. But I need to have two headings with different CSS format for day and for month.
My idea is to use save_post hook, separate these two figures picked in date/time picker and save them to another custom fields “day” and “month” as format e.g. “1” and “JAN”.
I tried code below (for month), but it is not working
add_action('save_post', 'separateEventStartDate', 10, 2); function separateEventStartDate($post_id) { // if date/time is not picked, return if (empty(get_post_meta($post_id, 'event_start', true))) { return; } else // load picked date and time to variable $eventStart = $_POST['pods_meta_event_start']; // change format to abbreviated month e.g. "JAN" $eventStartMonth = date("M", strtotime($eventStart)); // save month to custom field update_post_meta($post_id, 'month', $eventStartMonth); }
What am I asking:
1) Is it possible to make it this way?
2) What is the default format how PODS save date and time from picker. Is it object, array, string?
3) Do I use correct functions to get/save meta fields?
4) Is there a way to display (console, admin page) variable value to check it?Thank you for any ideas!
- The topic ‘Split date/time to custom fields’ is closed to new replies.