checkbox list not saved in my custom Table
Support › MB Custom Table › checkbox list not saved in my custom TableResolved
- This topic has 2 replies, 2 voices, and was last updated 4 years, 11 months ago by
JeanROUSTAN.
-
AuthorPosts
-
May 12, 2020 at 3:02 PM #19580
JeanROUSTAN
ParticipantHi,
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 youfunction 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' );
May 12, 2020 at 3:48 PM #19581Long Nguyen
ModeratorHi,
Could you please let me know the data type of column which saves
checkbox_list
value? I’m just using typeTEXT
and it saves the serialized string in the custom table as well. See my screenshots
https://cl.ly/5dd61aea3a8f
https://cl.ly/092a542c5485Here 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; }
May 14, 2020 at 5:11 PM #19599JeanROUSTAN
ParticipantI 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 -
AuthorPosts
- You must be logged in to reply to this topic.