Conversation
supportI would like to have the following features: 1) default value (current time) 2) timestamp in unix format Thanks, Christoph https://wordpress.org/plugins/acf-date-time-picker/
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')));
What about having a default value? Thanks, Christoph
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')));
I mean if the user does not enter a value, the current date/time should be used.
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 }
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.
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.
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')));
What about having a default value? Thanks, Christoph
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')));
I mean if the user does not enter a value, the current date/time should be used.
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 }
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.
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.