Support

Account

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;
    }