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

    (@tw2113)

    The BenchPresser

    I’d check out https://github.com/WebDevStudios/CMB2/wiki/Field-Types#text_date if you’re wanting to have the values saved as a timestamp. There’s a couple others as well, for different situations you may have.

    Thread Starter ajwah

    (@ajwah)

    I am aware of those alternatives but they pose a problem of user experience.
    I need to register events a date with from -> until time. An event may only be registered for one day. When querying the database I need to order them by date and starting time.

    The problem with using text_datetime_timestamp to represent both ends of the time interval is that the admin user has the ability to choose two different days. e.g. and event starting on Monday 1pm until Friday 3pm.

    As such, in my current set up, it would be ideal if there was a callback that would allow me to modify the text_time fields to be converted to amount of seconds so I could add the epoch amount of the text_date field(which I currently am using to represent the day) and sort my db query according to from field.

    So does cmb2 allow me to modify how it persists the data to the database?

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Yes, these two filters will allow you to override the meta-saving, and deal with the value how you want.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    You can also use the 'sanitization_cb' field parameter for adding a sanitization callback, where you can manipulate the value as you want before CMB2 handles the saving for you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Saving text_time as unix timestamp instead’ is closed to new replies.