• Resolved gamelust

    (@gamelust)


    Hello. I’ve run into an odd problem and have run out of ideas as to why this is occurring. I was hoping maybe someone has had this issue before and can point me in the right direction so I can clear this bug up.

    I’m on cmb v2.9, the site is running on PHP 7.2.34 with WordPress 5.8.1, and I have tried disabling plugins, changing PHP versions, and all of the troubleshooting basics.

    So, what’s actually happening. I’m using a metabox with a type => text_date_timestamp. When I use the datepicker to choose a date, it stores the date in the database with the correct timestamp(1630454400). When you view the post on the front-end, the date shows up correctly(September 1, 2021). However, if you edit the post, the datepicker will have the current month & day with the last 4 digits of the timestamp in place of the year(09/10/4400). This odd date issue also pops up when adding the metabox as a sortable column while browsing all posts of the post type.

    I have also tried changing these to text_datetime_timestamp and get the same messed up dates in the back end.

    Here is the code we use to set up the metabox:

    $cmb_schedule->add_field(array(
        'name' => 'Class Start Date',
        'desc' => '<strong>Required</strong>',
        'id' => $prefix . 'class_start_date',
        'type' => 'text_date_timestamp',
        'attributes'  => array(
            'required'    => 'required',
        ),
        'column' => array(
            'position' => 2,
        ),
    ));

    Thanks for taking the time to look at this for me and (hopefully) telling me where we screwed up.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just to confirm, and also help try to simplify local recreation, this is happening when this is the only field for the post, correct?

    Thread Starter gamelust

    (@gamelust)

    Ohh, I wish it were that simple. No, there are quite a bit of metaboxes on this site on a wide variety of post types. It was an existing site and this bug quite frankly came out of nowhere. Everything had seemed to work fine until the recent WordPress upgrades. This particular site has been up for at least 3+ years.

    I’ve included all the metaboxes that we have created for this particular post type into pastebin. Here is the link. https://pastebin.com/Wj43y8kL

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Thus far at least, I’m not having any issues with this as described.

    I copy/pasted your pastebin above and changed only the object type. Saved a post with the dates filled in and these are the results of get_post_meta() for those fields:

    '_cmb_class_start_date' => 
        array (size=1)
          0 => string '1568764800' (length=10)
      '_cmb_class_end_date' => 
        array (size=1)
          0 => string '1631750400' (length=10)
      '_cmb_class_start_time' => 
        array (size=1)
          0 => string '08:00 PM' (length=8)
      '_cmb_class_end_time' => 
        array (size=1)
          0 => string '11:00 PM' (length=8)
    

    When exiting the post editor and then clicking to edit again, the dates are showing up as expected.

    Definitely not discounting your experiences here, but just stating that I haven’t managed to recreate thus far. Possible that other plugins are playing parts in this issue.

    Thread Starter gamelust

    (@gamelust)

    Yes, the data in the database is always correct. The only time I run into problems is when viewing the post to update it, or when it’s displayed on post type list in the back end. Also, as I said before, I tried to see if disabling all plugins had any effect, it did not.

    The thing that really throws me off is that this is not consistent at all. Sometimes the dates are correct, other times they’re not. That’s why I’m having trouble pinpointing a cause, I can’t find a consistent result or cause.

    Here’s some screenshots of what I’m running into.

    Here’s the back end for the Class post type.

    Picture of the metaboxes on an individual class which has bad dates in the date picker.

    Lastly, a picture of the database meta entry for _cmb_class_start_date with the same post_id as previous image.

    Not sure if any of this sheds any light on what may be happening here.

    Could it be the sheer volume of meta data this site generates? They delete the entire schedule and re-upload a new schedule every single day and have done so for the past 3+ years.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any news or changes here? Any customizations outside of the CMB2 configurations going on that could be contributing?

    That does feel rather excessive where they’re deleting and recreating EVERYTHING because the more data you acquire to include each cycle, the larger the database is going to eventually grow. However, I don’t think that would have anything to do with the values stored or calculated to be stored.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Need Help: Weird Issue with Timestamps & the Datepicker’ is closed to new replies.