• Resolved dvorinm3

    (@dvorinm3)


    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @dvorinm3

    Storage of dates is always in MySQL format (YYYY-MM-DD HH:MM).
    Formatting dates should be done while displaying.

    I assume you can create two modules in Elementor using the same date field and then set a custom format right?

    If you really need extra custom fields you could indeed do it like you suggested but it seems a bit cumbersome.
    You can use WordPress core functions for getting and updating metadata.

    Cheers, Jory

    Thread Starter dvorinm3

    (@dvorinm3)

    Great thanks! I overlooked or maybe after Elementor update there really is the field where I can change Date and Time format.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Split date/time to custom fields’ is closed to new replies.