Support MB Custom Post Type Display CPT in page Reply To: Display CPT in page

#11630
dhuydhuy
Participant

Below is the meta box of the page builder. I can select the Pricing table (CPT) via the post field. I'm stuck at pulling the meta boxes from the selected CPT.

add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array (
        'title' => 'Page',
        'id' => 'page',
        'post_types' => array(
            'page',
        ),
        'context' => 'after_title',
        'priority' => 'high',
        'fields' => array(
            
            array (
                'id' => 'section',
                'type' => 'group',
                'name' => 'Section builder',
                'fields' => 
                array (
                    0 => 
                    array (
                        'id' => 'section_pricing',
                        'type' => 'group',
                        'name' => 'Pricing',
                        'fields' => 
                        array (
                            0 => 
                            array (
                                'id' => 'pricing_table_id',
                                'type' => 'post',
                                'name' => 'Post',
                                'post_type' => 
                                array (
                                    0 => 'prices',
                                ),
                                'field_type' => 'select_advanced',
                            ),
                        ),
                        'default_state' => 'collapsed',
                        'groupfield' => 'text',
                        'collapsible' => true,
                        'visible' => true
                    ),
                    
                ),
                'clone' => 1,
                'sort_clone' => 1,
                'default_state' => 'collapsed',
                'collapsible' => true,
                'save_state' => true,
                'add_button' => 'Add section',
            ),
        ),
        'style' => 'seamless',
    );
    return $meta_boxes;
}

Meta boxes of CPT:

add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array (
        'title' => 'Pricing table',
        'id' => 'pricing-table',
        'post_types' => array(
            'prices',
        ),
        'context' => 'after_title',
        'priority' => 'high',
        'fields' => array(
            
            array (
                'id' => 'plan',
                'type' => 'group',
                'name' => 'Group',
                'fields' => 
                array (
                    0 => 
                    array (
                        'id' => 'plan_class',
                        'type' => 'text',
                        'name' => 'Class',
                    ),
                    1 => 
                    array (
                        'id' => 'plan_name',
                        'type' => 'text',
                        'name' => 'Name',
                    ),                  
                ),
                'clone' => 1,
                'default_state' => 'collapsed',
                'collapsible' => true,
                'add_button' => 'Add table',
                'group_title' => 'Table',
            ),
        ),
        'style' => 'seamless',
    );
    return $meta_boxes;
}