• Resolved Borneyak

    (@borneyak)


    I have a problem with the text_time field type. I put the text_time into my simple plugin like the snippet below. I also added the text_date_timestamp. I used basicly the same kind of php code for both to get the info from the database. The date one gives me the right info and the time one gives me 00:00 back, while the database has the time info stored.

    Setting up the metaboxes:

    $prefix = '_myevent_';
    
    $cmb->add_field( array(
                    'name'          => __( 'Date (start)', 'cmb2' ),
                    'id'            => $prefix . 'date_start',
                    'type'          => 'text_date_timestamp',
                    'date_format'   => 'j-m-Y',
            ) );
    
    $cmb->add_field( array(
                    'name'          => __( 'Time (start)', 'cmb2' ),
                    'id'            => $prefix . 'time_start',
                    'type'          => 'text_time',
                    'time_format'   => 'H:i',
            ) );

    Showing the info:

    if (!empty ( get_post_meta( get_the_ID(), '_myevent_date_start', true ) ) ) {
                $eventdatestart = esc_html( date("j F Y", get_post_meta( get_the_ID(), '_myevent_date_start', true ) ) );
            }
    echo $eventdatestart;
    
    if (!empty ( get_post_meta( get_the_ID(), '_myevent_time_start', true ) ) ) {
                    $eventtimestart = esc_html( date("H:i", get_post_meta( get_the_ID(), '_myevent_time_start', true ) ) );
                }
    echo $eventtimestart;

    What am i doing wrong? How can i get the time?

    • This topic was modified 6 years, 11 months ago by Borneyak.
Viewing 1 replies (of 1 total)
  • Thread Starter Borneyak

    (@borneyak)

    It’s solved. My mistake was that i used the php date() to return the time. That was not needed. Removing the date() solved my problem.

Viewing 1 replies (of 1 total)
  • The topic ‘text_time return empty, database contains right value’ is closed to new replies.