Custom Fields
Re-Envisioned
Support MB Custom Table checkbox list not saved in my custom Table

  • Creator
    Topic
  • #19580
    Resolved JeanROUSTAN
    Participant

    Hi,
    I have in my function file, a code to add fields in my custom post type (stock).
    When i create a new cpt, all the fields are saved in my custom table, except the data of my checkbox list. Everything worked fine until the last update of the extension.
    This is a part of my file. Can you tell me to fix something that worked before ? ūüôĀ
    Thank you

    function get_meta_box_stock( $meta_boxes ) {
        $prefix = '';
    
    $meta_boxes[] = array(
        'id' => 'creation_stock',
        'title' => esc_html__( 'Fiche', 'toto' ),
        'post_types' => array('stock' ),
        'context' => 'advanced',
        'priority' => 'default',
        'autosave' => 'false',
         'storage_type' => 'custom_table',  
        'table'        => 'my_stock_table', 
        'fields' => array(
                        array(
                'id' = $prefix . 'statut',
                'name' = esc_html__( 'Statut', 'toto' ),
                'type' = 'radio',
                'placeholder' = '',
                'options' = array(
                    'dispo' = esc_html__( 'dispo', 'toto' ),
                    'reserve' = esc_html__( 'réservé', 'toto' ),
                    'option' = esc_html__( 'optionné', 'toto' ),
                    'bientot' = esc_html__( 'bient√īt √† la vente', 'toto' ),
                ),
                'inline' = 'true',
                'std' = 'dispo',
            ),
    
            array(
                'id' =$prefix . 'eligibilite',
                'name' =esc_html__( '√Čligibilit√©', 'toto' ),
                'type' ='checkbox_list',
                'options' array(
                    'Pinel' =esc_html__( 'Pinel', 'toto' ),
                    'Malraux' =esc_html__( 'Malraux', 'toto' ),
                    'LMNP' = esc_html__( 'LMNP', 'toto' ),
                    'LMP' = esc_html__( 'LMP', 'toto' ),
                    'PTZ' = esc_html__( 'PTZ', 'toto' ),
                ),
                'inline' = 'true',
            ),
    
        ),
    );
    
    return $meta_boxes;
    
    }
    add_filter( 'rwmb_meta_boxes', 'get_meta_box_stock' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #19581
    Long Nguyen
    Moderator

    Hi,

    Could you please let me know the data type of column which saves checkbox_list value? I’m just using type TEXT and it saves the serialized string in the custom table as well. See my screenshots
    https://cl.ly/5dd61aea3a8f
    https://cl.ly/092a542c5485

    Here is my sample code

    add_action( 'init', 'prefix_create_table' );
    function prefix_create_table() {
        if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
            return;
        }
        MB_Custom_Table_API::create( 'my_custom_table', array(
            'address' => 'TEXT NOT NULL',
            'phone'   => 'TEXT NOT NULL',
            'email'   => 'VARCHAR(20) NOT NULL',
            'checklist'   => 'TEXT NOT NULL',
        ), array( 'email' ) );
    }
    
    add_filter( 'rwmb_meta_boxes', 'custom_table_fields' );
    function custom_table_fields( $meta_boxes ) {
        $meta_boxes[] = array(
            'title'        => 'Meta Box Title',
            'storage_type' => 'custom_table',    // Important
            'table'        => 'my_custom_table', // Your custom table name
            'fields'       => array(
                array(
                    'id'   => 'address',
                    'type' => 'text',
                    'name' => 'Address',
                ),
                array(
                    'id'   => 'phone',
                    'type' => 'text',
                    'name' => 'Phone',
                ),
                array(
                    'id'   => 'email',
                    'type' => 'email',
                    'name' => 'Email',
                ),
                array(
                    'id' => 'checklist',
                    'name' => esc_html__( '√Čligibilit√©', 'toto' ),
                    'type' => 'checkbox_list',
                    'options' => array(
                        'Pinel' => esc_html__( 'Pinel', 'toto' ),
                        'Malraux' => esc_html__( 'Malraux', 'toto' ),
                        'LMNP' => esc_html__( 'LMNP', 'toto' ),
                        'LMP' => esc_html__( 'LMP', 'toto' ),
                        'PTZ' => esc_html__( 'PTZ', 'toto' ),
                    ),
                    'inline' => true,
                ),
            ),
        );
    
        return $meta_boxes;
    }
    
    #19599
    JeanROUSTAN
    Participant

    I don’t know why but, I deleted all of my cpt and created new ones. The problem is gone, as it came. I have not changed my function file. It’s very strange but the most important it’s working fine now.
    Thx

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash