Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Bartosz Romanowski

    (@toszcze)

    You can format the date and time using PHP date() function – please check FAQ for more details.

    For example, to display the timestamp you can use this code:

    echo date('U', strtotime(get_field('date_and_time_field')));

    Thread Starter Christoph Bratschi

    (@cbratschi)

    What about having a default value?

    Thanks,
    Christoph

    Plugin Author Bartosz Romanowski

    (@toszcze)

    Do you mean the format set in the WP settings?
    This should work:

    echo date(get_option('date_format').' '.get_option('time_format'), strtotime(get_field('date_and_time_field')));
    Thread Starter Christoph Bratschi

    (@cbratschi)

    I mean if the user does not enter a value, the current date/time should be used.

    Plugin Author Bartosz Romanowski

    (@toszcze)

    OK, I understand. But I don’t think this is a good idea to add this feature to the plugin (by the way: the built-in ‘Date’ field doesn’t return a default value as well).

    You can display the current time using the following code:

    if(empty(get_field('date_and_time_field'))) { // check if the field is empty
        echo date('Y-m-d H:i:s'); // or any other format
    }

    Thread Starter Christoph Bratschi

    (@cbratschi)

    I am using a repeater field and need a way to attach a timestamp to each item. Therefore the actual date has to be stored. It is a newsticker. I will write my own plugin for this case. A simple input field is sufficient, I don’t need a date/time picker.

    Plugin Author Bartosz Romanowski

    (@toszcze)

    In this case you don’t need to write a plugin – just use ‘acf/update_value’ action (https://www.advancedcustomfields.com/resources/acfupdate_value/) and update the input field with the current timestamp.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change Requests’ is closed to new replies.