Home › Forums › Feature Requests › Date Time Picker should optionally save timestamp › Reply To: Date Time Picker should optionally save timestamp
@hatsumatsu ‘s solution works great, except I can’t seem to be able to make it work with a date field assigned to a custom taxonomy. I’m using it for a date picker like this:
/**
* Convert values of ACF core date pickers from Ymd 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_wp_date( $value, $post_id, $field ) {
if( $value ) {
$value = strtotime( $value );
}
return $value;
}
add_filter( 'acf/update_value/type=date_picker', 'acf_save_as_wp_date', 10, 3 );
/**
* Convert values of ACF core date pickers from timestamp to Ymd
* @param string $value unmodified value
* @param int $post_id post ID
* @param object $field field object
* @return string modified value
*/
function acf_load_as_acf_date( $value, $post_id, $field ) {
if( $value ) {
$value = date( 'Ymd', $value );
}
return $value;
}
add_filter( 'acf/load_value/type=date_picker', 'acf_load_as_acf_date', 10, 3 );
Tried adding the name of taxonomy, like $value = strtotime( $value, 'event_dates' );
and $value = date( 'Ymd', $value, 'event_dates' );
as well, but I don’t know if that’s at all correct way of doing it.
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.