Custom Fields
Re-Envisioned
Support MB Custom Table Custom post type not saved in the new custom table

This topic contains 2 replies, has 1 voice, and was last updated by  JeanROUSTAN 2 months, 2 weeks ago.

  • Creator
    Topic
  • #15606
    Resolved
    JeanROUSTAN
    Participant

    Hi,
    i’ve successfully created a new custom table named ‘collaborateur_table’ with some fields.
    I’ve a custom post type named ‘collaborateur’ with fields created like that :

    function get_meta_box_collaborateur( $meta_boxes ) {
            $meta_boxes[]= array(
            'id' =>   'creation_collaborateur',
            'title' => esc_html__( 'Fiche collaborateur', 'textdomain' ),
            'post_types' => array( 'collaborateur' ),
            'context' => 'advanced',
            'priority' => 'default',
            'autosave' => false,
            'storage_type' => 'custom_table',    
            'table'        => 'collaborateur_table', // my custom table name
            'fields' => array(
    array(
                    'id' => 'title',
                    'type' => 'text',
                    'name' => esc_html__( 'title', 'textdomain' ),
                    ),
    array(
                    'id' => 'nom',
                    'type' => 'text',
                    'name' => esc_html__( 'Nom', 'textdomain' ),
                    ),
    [ etc...]
             ),
    
        );
    
        return  $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'get_meta_box_collaborateur' );

    Everything is correctly displayed
    But when i publish a new post type ‘collaborateur’, only the title is registered in the wp_posts table. No new entries is registered in my custom_table.
    Did I forget something to be able to save my custom fields in my new table ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #15607

    JeanROUSTAN
    Participant

    I’ve forgotten, my custom fields are not saved too. When I re-edit my new post type, only the title is registered

    #15608

    JeanROUSTAN
    Participant

    Sorry for the inconvenience, I just found my mistake.
    The fields in my table were different from the fields. I left the prefix …
    i fixed that and now all is working fine 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.