Home › Forums › Backend Issues (wp-admin) › Datepicker save format › Reply To: Datepicker save format
Yes
add_filter('get_post_metadata', 'format_rehub_offer_coupon_date', 10, 5);
function format_rehub_offer_coupon_date($value, $object_id, $meta_key, $single, $meta_type) {
// $value will initially be NULL
// this happens before data is retrieved
// returning anything other than NULL will result in short circuit of WP function
// this might break the acf input in admin
// if it does un-comment the following if block
/*
if (is_admin()) {
return $value;
}
*/
// see if it's the meta key we want to format
if ($meta_key != 'rehub_offer_coupon_date') {
// not our field
return $value;
}
// remove this filter to prevent infinite loop
remove_filter('get_post_metadata', 'format_rehub_offer_coupon_date', 10);
// get the value of field
$new_value = get_post_meta($object_id, 'rehub_offer_coupon_date', true);
// return if empty
if (empty($new_value)) {
return $value;
}
// correctly format the value for theme
$value = date('Y-m-d', strtotime($new_value));
// re-add this filter
add_filter('get_post_metadata', 'format_rehub_offer_coupon_date', 10, 5);
// return new value
return $value;
}
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.