Support » Plugin: CMB2 » Date field doesn't display the value in admin

  • Resolved bill_baroud02



    I’ve got 2 date fields, one is working perfectly but the other does not show the value in admin (the value is correctly saved in DB).

    My code :

    $evt_general = new_cmb2_box( array(
    		'id'            => $prefix . 'general',
    		'title'         => __( 'Général', 'cmb2' ),
    		'object_types'  => array( 'evenement'), // Post type
    		'context'       => 'normal',
    		'priority'      => 'high',
    		'show_names'    => true, // Show field names on the left
    		'cmb_styles'    => true, // false to disable the CMB stylesheet
    	) );
    $evt_general->add_field( array(
    		'name' => __( 'Date de début', 'cmb2' ),
    		'id'   => $prefix . 'date_debut',
    		'type' => 'text_date',
    	) );
    	$evt_general->add_field( array(
    		'name' => __( 'Date de fin', 'cmb2' ),
    		'id'   => $prefix . 'date_fin',
    		'type' => 'text_date',
    	) );

    Any idea of what could be wrong ?


Viewing 15 replies - 16 through 30 (of 30 total)
  • Sure. I’m not at home today but I reproduced the issue on a different project at work.

    So the version of the plugin is the later (Version 2.0.6). I’ve installed it from the back-office of wordpress.

    This is the code I used to reproduce the issue:


    As you can see I used your snippet (otherwise the date format was wrong) but the issue is the same I explain before.

    Thank for your help 🙂

    Plugin Author Michael Beckwith


    The BenchPresser

    I think I made a minor goof in regards to pointing out the earlier snippet. I believe that is meant more for the text_date_timestamp field, and not the text_date. That said, I don’t have a solution at the moment for European dates with just text_date.

    Any updates? I’m facing the same problem Carine described, with text_date.

    BTW, I’ve just tried to switch to text_date_timestamp but the problem persists in my case.
    EDIT: More precisely after switching to text_date_timestamp and deleting old meta keys saved in text_date format, the date fields do not even get saved to the database. Here is my code:

    add_filter( 'cmb2_localized_data', 'prefix_cmb_set_date_format' );
    function prefix_cmb_set_date_format( $l10n ) {
    	// Set your date format replacing 'dd-mm-yy' (UK format)
        $l10n['defaults']['date_picker']['dateFormat'] = 'dd/mm/yy';
        return $l10n;
    	$cmb_evento->add_field( array(
    		'name' => __( 'Data inizio', 'cmb2' ),
    		'desc' => __( 'La data del primo giorno dell'."'".'evento', 'cmb2' ),
    		'id'   => $custom_fields_prefix . 'data_inizio_evento',
    		'type' => 'text_date_timestamp',
    	) );
    	$cmb_evento->add_field( array(
    		'name' => __( 'Data fine', 'cmb2' ),
    		'desc' => __( 'La data dell'."'".'ultimo primo giorno dell'."'".'evento<br/>Se coincide con la data iniziale, questa si può lasciare vuota.', 'cmb2' ),
    		'id'   => $custom_fields_prefix . 'data_fine_evento',
    		'type' => 'text_date_timestamp',
    	) );
    Plugin Author Michael Beckwith


    The BenchPresser

    Have you verified that you have no post meta keys that match what the prefix is plus “data_inizio_evento” or “data_fine_evento” ?

    I’m having the same issue, with both text_date_timestamp and text_date.

    The snippet you posted is not making any changes. The date is saved in the DB but if I pick a day gratter than 12 after saving the post it is not displayed on the CMB2 date field, though it is in the DB and I can access it with the get_post_meta function

     * Fix for date format
    function customDateFormat( $data ) {
    	$data['defaults']['date_picker']['dateFormat'] = 'dd/mm/yy';
    	return $data;
    add_filter( 'cmb2_localized_data', 'customDateFormat' );
     * Events fields
    function eventSideSingle() {
    	global $home_slides;
    	$cmb = new_cmb2_box( array(
    		'id'           => __PREFIX__ . 'eventSideSingle',
    		'title'        => 'Fecha del evento',
                    'object_types' => array( 'event' ),
    		'context'      => 'side',
    		'priority'     => 'default',
    		'show_names'   => true,
        $cmb->add_field( array(
            #'name' => 'Fecha del Evento',
            'desc'  => '...',
    		'id'      => __PREFIX__ . 'eventDate',
            'type' => 'text_date',
        ) );

    WP version: 4.4
    CMB2 plugin version: 2.1.2

    Hi there,

    you should take a look at this conversation:

    There is a fork from @yivi that you can use until a new release.

    The fork:

    It works perfectly, I’m currently using it on my personal website.

    Hope it will help!

    Thank you for the quick answer. It is still not working after I changed to the forked version.

    Nevermind. I was using text_date, changed to text_date_timestamp and now it is displaying the date after post save but is a differnt one from what I picked. Some localization problem for sure.

    Yeah, I had exactly the same problem before using yivi’s fork.

    I don’t understand why it doesn’t work on your project.

    However, I’ve also made a fork to fix that issue in another way (but yivi’s fork is better), maybe you can try to use mine:

    Please read the “readme” file in order to use the fork correctly.

    Let me know if it works…

    Thank you so much! Your fork worked!

    And I realised yivi’s one was working too.

    I just had to set: ‘date_format’ => ‘d/m/Y’.

    Really thankful for your help!

    sorry, this is an automatic translation.

    CMB2 use as a plugin Wp (4.4.2) and I have the problem of the date field.

    Carine has posted the solution, but I do not understand what files you search and download from GitHub, and then replace them with those of the original plugin WP.

    Thanks in advance for any help


    Hi K15Lmk98,

    There is a readme file in my GitHub project where I specify the file I have modified and how to use the modifications:

    You can use yivi’s fork or mine using git (clone the project on your computer), but if you’re not familiar with Github/Git, you can just copy the content of the text_date_timestamp() function (CMB2_Sanitize.php line 211) and then replace the content of the same function in the file in your own project (you will find this file in the CMB2 plugin directory).

    Don’t forget to follow what I have written in the readme file (Usage) and it should be good.

    Good luck!

    Automatic translation.

    Carine Thanks for the reply.
    I still have the problem. Surely I’m missing something.
    If you have time and want to see the list Thank you.

    I replaced the text_date_timestamp() function, even if it was not necessary, because the plugin Wp up to date.

    In the file that I include in Wp I have this code:

    add_filter( 'cmb2_localized_data', 'carine_custom_cmb2_date_format' );
    function carine_custom_cmb2_date_format( $data ) {
    	$data['defaults']['date_picker']['dateFormat'] = _x( 'dd/mm/yy', 'Valid formatDate string for jquery-ui datepicker','cmb2' );
    	$data['defaults']['date_picker']['firstDay'] = 1; // Set 1 for Monday or 0 for Sunday (default)
    	return $data;
    add_action( 'cmb2_init', 'carine_register_page_metabox' );
    function carine_register_page_metabox() {
    	// Start with an underscore to hide fields from custom fields list
    	$prefix = '_carine_';
    	 * Metabox to be displayed on a single page ID
    	$cmb_about_page = new_cmb2_box( array(
    		'id'           => $prefix . 'metabox',
    		'title'        => __( 'Page Metabox', 'cmb2' ),
    		'object_types' => array( 'page', ), // Post type
    		'context'      => 'normal',
    		'priority'     => 'high',
    		'show_names'   => true // Show field names on the left
    	) );
    	$cmb_about_page->add_field( array(
    		'name' => __( 'Test Date Picker', 'cmb2' ),
    		'desc' => __( 'field description (optional)', 'cmb2' ),
    		'id'   => $prefix . 'textdate',
    		'type'          => 'text_date_timestamp',
    		'date_format'   => 'd\/m\/Y' // Default: 'm\/d\/Y'
    	) );

    Thanks, Claudio_

Viewing 15 replies - 16 through 30 (of 30 total)
  • The topic ‘Date field doesn't display the value in admin’ is closed to new replies.