Custom Fields
Re-Envisioned
Support MB Custom Table PHP Code to create/update field value in Custom Table ?

  • Creator
    Topic
  • #30605
    justdoit123
    Participant

    I tried to search in your forum and read your document : https://docs.metabox.io/extensions/mb-custom-table/#using-custom-tables

    But i cannot see any post about this : PHP Code to create/update field value in Custom Table ?

    my wordpress/php is limited.

    But i think this is essential topic.

    Please help. I need some example for PHP Code to create/update field value in Custom Table ?

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #30606
    justdoit123
    Participant

    also how do i use short code and php code to show custom field value from custom table ??

    i try this short code but it does not show value "name" for User ID = 1 :
    [rwmb_meta id="name" object_id="1" storage_type="custom_table" table="wp_test"]

    here is my custom table

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'        => __( 'Test', 'your-text-domain' ),
            'id'           => 'test',
            'type'         => 'user',
            'storage_type' => 'custom_table',
            'table'        => 'wp_test',
            'fields'       => [
                [
                    'name'       => __( 'Name', 'your-text-domain' ),
                    'id'         => $prefix . 'name',
                    'type'       => 'text',
                    'save_field' => 1,
                ],
                [
                    'name'       => __( 'Phone', 'your-text-domain' ),
                    'id'         => $prefix . 'phone',
                    'type'       => 'text',
                    'save_field' => 1,
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    #30626
    Long Nguyen
    Moderator

    Hi,

    Your shortcode is missed the attribute object_type, please see on this topic https://metabox.io/support/topic/shortcode-to-show-user-meta-type-select-avanced/

    [rwmb_meta id="name" object_id="1" storage_type="custom_table" table="wp_test" object_type="user"]
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.