@hube2 That was it! The plugin in question had an unnecessary capability check that caused it fail to register the field.
Thanks for the prompt support
@hube2 As mentioned in my first post my field group is created via acf_add_local_field_group()
using the acf/init
hook.
Anything else I can provide to help investigating this?
Okay, so it’s about taking the filter / actions approach. This way converting the field value when saving a post is not enough, you also have to convert the value back when the field is loaded by ACF otherwise the date picker UI doesn’t work:
This works for me:
/**
* Convert values of ACF core date time pickers from Y-m-d H:i:s to timestamp
* @param string $value unmodified value
* @param int $post_id post ID
* @param object $field field object
* @return string modified value
*/
function acf_save_as_timestamp( $value, $post_id, $field ) {
if( $value ) {
$value = strtotime( $value );
}
return $value;
}
add_filter( 'acf/update_value/type=date_time_picker', 'acf_save_as_timestamp', 10, 3 );
/**
* Convert values of ACF core date time pickers from timestamp to Y-m-d H:i:s
* @param string $value unmodified value
* @param int $post_id post ID
* @param object $field field object
* @return string modified value
*/
function acf_load_as_timestamp( $value, $post_id, $field ) {
if( $value ) {
$value = date( 'Y-m-d H:i:s', $value );
}
return $value;
}
add_filter( 'acf/load_value/type=date_time_picker', 'acf_load_as_timestamp', 10, 3 );
+1 for an option to save as timestamp, seems way more flexible to me.
(Can’t view James’ reply since it’s marked private)
I have a site with complex timestamp-based queries using the Date and Time Picker Addon, but after the latest ACF update this is broken in combination with the newly introduced date and time picker in ACF core. So I’m basically left with either coming up with a hook to convert the data into timestamp everytim a date is saved (seems rather hacky to me) or rewriting all of my queries? o_o
An option to save data as timestamp would be greatly appreciated!
You’re absolutely right, the JS in question was added by the Validated Field addon. Sorry for not checking before posting.
I started a thread on the wordpress.org in case someone has these problems, too.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.