soderlind / acf-field-date-time-picker Goto Github PK
View Code? Open in Web Editor NEWDate and Time Picker field for Advanced Custom Fields v3 and v4
License: GNU General Public License v2.0
Date and Time Picker field for Advanced Custom Fields v3 and v4
License: GNU General Public License v2.0
I got the files correctly downloaded, thank you for the advice before.
I'm wondering if there might be an easy way to add am/pm to the display of the time for when editing the field? Maybe a feature request for a future release? In the meantime, I'd be happy to implement a simple workaround if you had one.
Thanks!
It would be helpful if there was an option make the return value the UNIX timestamp rather than the formatted date/time.
I'm currently running ACF 4.2.2 and ACF Field Date Time Picker 2.0.1.1 and I have two fields date and time picker fields set up. When I choose my times, it seems a little buggy, but when I click Publish, it clears out my selections and does not save.
Is it possible to compare two dates or times using a PHP logical operator?
I currently have two fields; a start date and time, and an end date and time. I'm wanting to create a 'date' section for each event on my site but sometimes the date is the same, and I don't want it to echo out both dates for the same day... only the time.
So, I thought this would work; but alas it's comparing the two fields, which although have the same date... the time is different and therefore isn't true.
<?php $project_start_date = DateTime::createFromFormat('U', get_field('start_date_and_time')); ?>
<?php $project_end_date = DateTime::createFromFormat('U', get_field('end_date_and_time')); ?>
<?php if ( get_field('start_date_and_time') && get_field('end_date_and_time') ) : ?>
<?php if ( get_field('start_date_and_time') == get_field('end_date_and_time') ) : ?>
<h3><?php echo $project_start_date->format('D d F'); ?></h3>
<?php else : ?>
<h3><?php echo $project_start_date->format('D d F'); ?><br/>
<?php echo $project_end_date->format('D d F'); ?></h3>
<?php endif; ?>
<?php endif; ?>
I've set the timezone to UTC-5 (Montreal time) in the wordpress setting but it seems that your plugins doesn't save upon this setting. The timestamp created is set to UTC 0. Is it possible for you to link your plugin with the WP timezone setting ?
Thanks
Opening a new issue since I didn't see one specific on this.
I have version 2.0.11 with ACF 4.2.2 installed on WP 3.5.1. On initial save, my post gets an offset of -4 hours. So if I select 9/24/2013 12:00pm, it saves initially as 9/24/2013 8am. When I go back and correct the time and save again, the post retains the correct time.
This is all good but my client is not happy with that functionality and expects it to be fixed. I am looking at the code myself but since others have experienced it too, it would be nice to have it fixed.
Thanks. Any tips on a decent workaround are welcome.
I was trying to use this plugin with a custom date format that did not include minutes. When saving posts, the post would appear to save correctly, but the date was never saved. It would be empty in the post page and the DB would have an empty field stored for the date.
The formats I was using were
'date_format' => 'DD dd MM yy'
and
'time_format' => 'HH'
I was working to debug and added a new field with default format and it saved correctly. I assume this is related to the plugin not understanding a date format without minutes.
Here is the relevant ACF export (you will want to change post_type
from custom type event
to test).
<?php
register_field_group(array (
'id' => 'acf_champs-evenement',
'title' => 'Champs: Événement',
'fields' => array (
array (
'key' => 'field_53591c3095e97',
'label' => 'Date de début',
'name' => 'date_start',
'type' => 'date_time_picker',
'required' => 1,
'show_date' => 'true',
'date_format' => 'DD dd MM yy',
'time_format' => 'HH',
'show_week_number' => 'false',
'picker' => 'slider',
'save_as_timestamp' => 'true',
'get_as_timestamp' => 'false',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'event',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
Hi @soderlind
I'm Elliot, the developer behind ACF
Just wanted to say great work on creating the v4 compatible field type!
I've just put together a template for creating a plugin which supports v3 and v4 field types. You can check it out here: https://github.com/elliotcondon/acf-field-type-template
It would be great if you could use the template to wrap up both the field files into 1 plugin!
Let me know,
Cheers
Elliot
I have added some events that have a custom field for when the event is on, then i have used your plugin for the time it starts. When i am ordering the custom query by the meta_value for the start time they are all over the place. Then i found that the timestamp is saved as the creation date of the post with the time.
eg. event is on 2nd August at 10:00am, i have a field for start_date and start_time but because the post was created on 30th June, the timestamp is saved as 30th June 10:00am
Any idea how i can fix this?
Fatal error: Call to a member function getTimestamp() on a non-object in /wp-content/plugins/acf-field-date-time-picker/date_time_picker-v4.php on line 297
$field : Array ( [value] => [label] => Von [time_format] => hh:mm [show_date] => true [date_format] => yy-mm-dd [show_week_number] => false [picker] => slider [save_as_timestamp] => true [key] => field_5189606e82e05 [name] => von [type] => date_time_picker [order_no] => 1 [instructions] => [required] => 0 [id] => acf-field-von [class] => date_time_picker [conditional_logic] => Array ( [status] => 0 [rules] => Array ( [0] => Array ( [field] => null [operator] => == [value] => ) ) [allorany] => all ) )
$value : 2013-07-18 14:00
You better check the value against the time_format chosen in the ACF-Backend. At that example the time_format alows only 12h not 24h.
Best regards
Hi,
I'm trying to set up a simple if statement to run if the date/time has already passed and I realized that some of the data was stored in timestamp format and some in strtotime, It looked like it happened at the update.
Is there any way I can convert the data stored in timestamp format to strtotime or vice verse?
With version 2.0.7 and 2.0.6, when we change the format of the date from "mm/dd/yy" to "dd/mm/yy" (for example), the date will change, for example :
10 April 2013
before: 04/10/2013
after : 10/04/2013 -> Everything seems ok BUT, if you click on this date to open the date picker, you can see that 04 October 2013 is selected !! (instead of 10 April)
If you update several times the page in Wordpress without making any change, the value is modified automatically: 10/04/2013, then 04/10/2013, then 10/04/2013, then 04/10/2013...
If your day number is more than 12 (example : 25 April 2013), the initial date 04/25/2013 disappears, the field is empty (probably because there isn't any month after 12. 25 is too big.)
The version 2.0.5. has not this problem.
If you don't change the initial format "mm/dd/yy", everything is ok.
For your information, my language is French in wp_config.php (fr-FR)
Best regards
When using just the timepicker (not date and timepicker together) the field doesn't appear as a dropdown but just a text box. This is breaking some functionality with my site as it changes the value type when I go back to edit a post, etc. I am running ACF Version 4.3.8 and the latest Date and Timepicker Add-on version 2.0.14.
Any help would be greatly appreciated!
When adding times to a post it leads to an PHP error or something. So the page kind of dies and keeps white.
Setting times to be not stored in UNIX timestamp kind of fixes the bug, but the time will not be displayed anyway
My date and time picker is used in a repeater field: the picker works on fields in existing rows but If I add a row, the picker does not appear when I focus on the field. To make it work I have to save the post.
I've just update ACF to version 5.0.7. It seems to me that it worked properly before update.
P.S.: I'm not getting any javascript error to focus on the field.
Any ETA on the next release of the beta? I can't seem to get it to work without those missing files even when doing some replacing from the old version.
Thanks for your hard work!
Hi, I found an issue and here is the details.
I have a datetime field on post, if I already saved a datetime for a post then tries to edit it, I can't change the year, no matter what I do the result won't change. The only way I can modify it is to delete the string first and then select again.
I remember seeing a log message from firebug console saying the date format is not correct when I tries to modify the year. This happens in the previous version. With the latest version ( ACF is latest as well), the log message is gone but the issue remains.
I tested with WordPress 3.8.3 and 3.9. Could you please take a look at this issue. Thank you!
Date and Time Picker Window not opening if rules are set by category type I have set Field Group to show for two categories.
When set categories are selected the field group is shown but the drop down is not.
I kept changing the options one by one and when I finally set the rules as Post type is equal to post the picker window is opening.
Wordpress - 3.5.1
ACF - 4.0.3
Date and Time Picker - 2.5
Can you please have a look at this...
I installed the plugin, and in a custom field see the option for Date and Time Picker. I save the settings, then go to a page that incorporates the custom fields (all others using ACF are fine). The field I saved as Date and Time picker is just a blank text field. If I click in it, no Date Picker appears. Nothing happens.
Using ACF 3.4.3, WP 3.4
I'm having an issue saving my posts with Date and Time custom fields assigned to them. The field ends up saving fine, but immediately after saving the post (or custom post type), I get a blank screen and have to navigate back to the admin area via a URL.
It's definitely related to the plugin. Plain posts and page save fine, but any post that has the custom fields assigned to it causes this issue.
I am using it in a multisite configuration and have implemented the fix describes in #16
Any suggestions?
This may be a known issue, my apologies if it's a duplicate item. The time picker doesn't seem to be showing up on the options add on. I don't see any JS errors when inspecting. I looked at the plugin myself to see if I could debug but I don't see anything wrong on the surface. Thanks.
I am trying to install the date & time picker to a WordPress website and every time I activate the plugin the entire website comes tumbling down, frontend and backend. The only way to get the site back again is to go in through SSH and delete the plugin folder.
I have installed the plugin on another website that uses many of the same plugins without an issue. I have also gone through the process of deactivating plugins to make sure there wasn't a conflict happening there.
The only real difference that I can see between the two sites is that the one where the plugin crashes everything is using a newer version of PHP. The plugin seems to be working on the second site (PHP 5.2.17) but failing when using the newer version on the first site (PHP 5.4.17).
I'm using the date format dd/mm/yy, however after saving the date either disappeared or came back in the wrong format. For example, saving 06/11/2013 would come back as 11/06/2013.
The problem is because the plugin uses the strtotime() PHP function which assumes the day and month be in a specific order. As a result I changed the update_value() function in file date_time_picker-v4.php as follows:
function update_value( $value, $post_id, $field ) {
$field = array_merge($this->defaults, $field);
if ($value != '' && $field['save_as_timestamp'] == 'true') {
if ($field['date_format'] == 'dd/mm/yy')
{
$value = str_replace('/', '-', $value);
}
$value = strtotime( $value );
}
return $value;
}
Otherwise, great plugin :) Thanks.
offending comma at beginning of array next to 'label'
$this->defaults = array(
, 'label' => __( 'Choose Time', $this->domain )
, 'time_format' => 'hh:mm'
, 'show_date' => 'true'
, 'date_format' => 'yy-mm-dd'
, 'show_week_number' => 'false'
, 'picker' => 'slider'
, 'save_as_timestamp' => 'true'
, 'get_as_timestamp' => 'false'
);
This is quite minor, pretty much aesthetic, but; the plugin name for WordPress in acf-date_time_picker.php
is formatted like an identifier :
/*
Plugin Name: Advanced Custom Fields: date_time_picker
...
rather than a title :
/*
Plugin Name: Advanced Custom Fields: Date and Time Picker Field
...
When used within the acf-form() front-end option, the date-picker doesn't show and when submitting the form, the time is modified to a different hour despite of what is manually written in the text field.
Error in trying to publish a post:
Fatal error: Call to undefined method DateTime::createFromFormat() in ..../wp-content/plugins/acf-field-date-time-picker/date_time_picker-v4.php on line 293
The date/time picker no longer shows up after updating.
Hi soderlind,
If you're using this on a child theme and attempt to use the plugin on the parent theme, wp_enqueue_script and wp_enqueue_style are not working correctly due to usage of get_stylesheet_directory_uri().
Changing this instead to get_template_directory_uri() works.
Not sure if you can make a check to see if the plugin is running in a child or parent theme, but I figured I'd highlight this issue at least for documentation.
ACF 5.0 Pro was released today and breaks compatibility with this plugin. Do you plan on adding v5 support soon?
Thanks!
Summary: Date/Time fields are being displayed as UNIX timestamps if added to the ACF Options page, and are also deleted if saved as timestamps.
Reproduced with: WordPress 3.6.1, 3.7 and 3.7.1 (latest) / ACF 4.2.2, 4.3.0, and 4.3.1 (latest), ACF: Date and Time Picker 2.0.11 (latest), ACF: Options Page 1.2.0 (latest).
Steps to reproduce:
Install and activate Advanced Custom Fields (either version listed above), ACF Date & Time Picker (latest version), ACF Options Page (latest version).
Add a new field group. Tell it to appear on the global “Options” page.
Add a “Date/Time” field to the field group. Tell it to be just a “Time Picker” field. Leave all other settings in their natural state.
Go to the Options page and fill out the field with a time.
Click “Save Options”.
At this point, you’ll notice that the field, when saved, then displays in the back-end Options page as a UNIX timestamp (which it should not be doing, according to its default settings, which say it should save as a timestamp but be returned as a human readable time). At this point, one of two things can happen:
Click “Save Options” again. The fields value then deletes itself.
Click on the “Options” page again in the sidebar to essentially refresh the page (refreshing the page directly isn’t reliable because it asks you if you want to submit the form again). Now the field should display it’s correct value (not a UNIX timestamp, something like 1:00 am). However, if you click “Save Options” again, it turns back into a timestamp.
This is the primary issue I’ve had, although I’ve also experienced issues with not being able to reorder fields in field groups that are displaying on the Advanced Options Page, as well as entire fields just disappearing.
Any help would be appreciated.
We added the Advanced Custom Fields: Date and Time Picker add-on and the jquery add-on is great for our end users. When we edit an existing item with a field designated as "Date and Time Picker" and choosing "Time Picker" as the type, the field is empty.
Setup: WP 3.5.2 (Network)
Theme: Twenty Twelve child
Active Plugins: Advanced Custom Fields
Advanced Custom Fields: Date and Time Picker
WP Super Cache
Akismet (network activated).
Thanks
As of a very recent version of ACF (probably 4.1.6), the date values are no longer showing up in the datepicker textbox.
Others seems to be having the same issue: http://wordpress.org/support/topic/field-values-do-not-show
Love this plugin! Looking forward to a fix for this problem :)
Hi again,
The files that are supposed to be in the "jQuery-Timepicker-Addon" directory are missing when the plugin is downloaded from GitHub as a zip file. Copying the files from the old version of the plugin (for ACF v3) works.
Although perhaps the css file should not actually be in this js directory?
Thanks!
At the moment, when using the plugin in a theme, I have to convert what should be booleans to the strings 'true' and 'false' for the following parameters:
show_date
show_week_number
save_as_timestamp
get_as_timestamp
ACF uses 1 and 0 for booleans and it would be useful if this plugin did the same.
Cheers
Desperately trying to get the time working for a music festival site.
Running a multisite install, with latest version of ACF, repeater and trying to use the date/time picker to add events. Just showing up as a text field - either installed as plugin or called from functions php.
wp- 3.81, ACF -4.3.4 repeater - 1.1.1 , acf-date-time - 2.0.12 (all latest), tried network , individual and theme installation, same issue
If I use the field with WPLANG set to blank or set to any language where there are no translation files, the field saves fine (timestamp).
If I set the language in WPLANG and have the files (in my project's case, fi_FI) the field saves as blank.
Incidentally if I don't save/retrieve as timestamp then it works fine no matter what language.
Possibly something the way translations are being applied to these fields?
// Event Time
register_field_group(array (
'id' => 'acf_event-time',
'title' => 'Event Time',
'fields' => array (
array (
'key' => 'field_5331c8494fb07',
'label' => 'Starts:',
'name' => 'start_date',
'type' => 'date_time_picker',
'required' => 1,
'show_date' => 'true',
'date_format' => 'dd M yy',
'time_format' => 'H.mm',
'show_week_number' => 'false',
'picker' => 'select',
'save_as_timestamp' => 'true',
'get_as_timestamp' => 'true',
),
array (
'key' => 'field_5331c8734fb08',
'label' => 'Ends:',
'name' => 'end_date',
'type' => 'date_time_picker',
'show_date' => 'true',
'date_format' => 'dd M yy',
'time_format' => 'H.mm',
'show_week_number' => 'false',
'picker' => 'select',
'save_as_timestamp' => 'false',
'get_as_timestamp' => 'false',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'gp_event',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'side',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
Hey
I'm using WP Version 3.7.0 with ACF Version 4.2.2 and this Plugin Version 2.0.11. I haven't changed anything in the settings of the Date&Time Picker and just added it to my form.
Currently I don't see the "Add Row" button I saw in the description video of the plugin and the date I picked is not shown after saving.
Does someone know what I'm doing wrong? Do I have to change some of the field settings?
Issue #45 incorrectly attributed a problem with some date formatting to dates lacking minutes. (That may or may not be an issue, I have not confirmed.)
There is an issue with some date formats with the date and time picker. It appears to be related to spaces in the date format, but that is only a first guess.
When using these formats, you can submit a post, but the date will not be saved. There is an empty record in the DB rather than a timestamp.
The relevant formats error causing formats are 'date_format' => 'DD dd MM yy'
and 'time_format' => 'HH'
Here is an ACF export of the problematic field group:
<?php
register_field_group(array (
'id' => 'acf_champs-evenement',
'title' => 'Champs: Événement',
'fields' => array (
array (
'key' => 'field_53591c3095e97',
'label' => 'Date de début',
'name' => 'date_start',
'type' => 'date_time_picker',
'required' => 1,
'show_date' => 'true',
'date_format' => 'DD dd MM yy',
'time_format' => 'HH',
'show_week_number' => 'false',
'picker' => 'slider',
'save_as_timestamp' => 'true',
'get_as_timestamp' => 'false',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'event',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
When I set the date format in the field to dd/mm/yy, it seems to be storing the day as the month, and the month as the day.
I would prefer to use the date format as dd/mm/yy as that as the date format we are using, and otherwise it will be confusing to the user.
Thanks,
Ben
Hi
I'm on ACF 5.0.3, thanks a lot for the compatibility upgrade :)
I noticed though that the get_as_timestamp
option isn't working as expected. While the value is delivered correctly in the frontend, it is also returned as a timestamp in the backend, and then the date/time pickers trip over it.
The logic is simple: In the backend, we always need the formatted value and never a timestamp. In the frontend, we need a timestamp iff get_as_timestamp
is on.
Given the filter chain load_value
(backend and frontend) → format_value
(only frontend), I suggest either to
load_value
orformat_value
.As of now, the code in load_value
and format_value
is identical, which in my eyes doesn't make sense.
Perhaps it's related to #14? Inputting time no longer saves on post save either.
Update: Scratch that, changing to 'default_value' fixed the issue.
When entering a new date and time (using either the dropdown or slider), the field populates correctly and the data is saved to the post meta table.
However, the data is not re-populated in the field input when after the post edit screen has reloaded.
Using ACF Version 4.1.5 and acf-field-date-time-picker Version 2.0.8 (installed as a plugin).
Hi,
Great addon for ACF, but we've encountered an issue if we set the time to 8 at night. It sets as morning 8AM, when its actually set to 8PM.
Thanks,
Tor Morten
Seems to be an issue with saving data to db. Using most up-to-date version of ACF: Version 4.1.5.1
View the screencast for a visual of the issue: http://www.screenr.com/nhBH
Can't understand - why, but this is it.
I have this datepicker field only in one category. When I'm creating a post - calendar window do not appear, but if post is already have been created (saved as draft or published) - it's OK.
Where can be the problem?
Hi, this is a great add on for acf, but while working I noticed that Date & Timepicker fields in a repeater are not being saved. This kept happening and although after few attempts field value eventually gets saved, that's inconvenient, not being able to save it with first attempt. No errors or warnings in console. Could you please take a look at this issue
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.