Using WordPress’s date/time format settings
-
I have a plugin that relies on CMB2.
That plugin does a lot of stuff with dates, and I have found that users are really picky about date/time formats. My plugin grabs the date/time formats from WordPress’s general settings, and uses those formats everywhere.
However, I cannot get those settings to work within a metabox with a text_datetime_timestamp field. If I add a ‘date_format’ parameter to that field, the field data will not save. Additionally, if the date format is set to ‘MM j, yy’, the format is displayed as ‘MayMay 05, 1717’ instead of ‘May 05, 2017’.
In other words, if I use this code:
$shift_meta->add_field( array( 'name' => __( 'Scheduled Start Date/Time', 'employee-scheduler' ), 'id' => $prefix . 'shift_start', 'type' => 'text_datetime_timestamp', 'date_format' => 'MM j, yy' ) );
the date will not save, and the format is displayed incorrectly.
Other people have reported these issues:
https://github.com/CMB2/CMB2/issues/765
https://github.com/CMB2/CMB2/issues/646
- The topic ‘Using WordPress’s date/time format settings’ is closed to new replies.