Custom Fields
Support MB Custom Table Same metabox fields in diferents CPT and diferents Custom Tables

  • Creator
  • #14249

    Hello, I have a metabox fields that are the same fields in some CPT.
    Is for that, that I write this:

    'post_types' => array( 'local' , 'negocio' ),

    But I want use MB Custom table, each table to each CPT, for this reason I write this:

    'storage_type' => 'custom_table',    // Important
    'table'        => array( 'locales' , 'negocios' ),

    But I think that 'table' not supported the array field.

    It's is posible to do this?
    Or I have to duplicate the metabox fieds?

    $meta_boxes[] = array (
        'id' => 'location',
        'title' => 'Códigos Post',
        'post_types' => array( 'local' , 'negocio' ), //$post_types,
            'context' => 'after_title',
            'style'   => 'seamless',
            'priority' => 'high',
            'geo' => array(
                'types' => array( 'establishment' )
            'storage_type' => 'custom_table',    // Important
            'table'        => array( 'locales' , 'negocios' ), //'locales', // Your custom table name
            'fields' => array(
                // Address field.


Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #14262

    Hello,don't worry about this, I created the own metabox fields for each custom table.



    Hello, sorry, I would like to reopen this thread.
    To see if I can save the fields of a metabox in different tables of the database in function of the cpt that is. Is that if I do not have to triple or quadruple many metabox fields ...


    Anh Tran


    I think to remove the duplicated code, you can store all the fields in a variable $fields and set it for 2 meta boxes (each for each post type):

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $fields = []; // your fields
        $meta_boxes[] = [
            'post_types' => 'post_type_1',
            'custom_table' => 'table_1',
            'fields' => $fields,
        $meta_boxes[] = [
            'post_types' => 'post_type_1',
            'custom_table' => 'table_1',
            'fields' => $fields,
        return $meta_boxes;
    } );

    That way, you don't have to repeat a large part of code. Also see this tutorial.


    What a good solution, I loved it, much easier to manage and with many fewer lines of code.

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.