Custom Fields
Re-Envisioned
Support MB Settings Page Display fileds from network settings page

  • Creator
    Topic
  • #30577
    Resolved gretch
    Participant

    Hi, I am a new user of Meta box and despite the doc I struggle to display my fields.

    The fields are in a network setting page (I use a wp multisite) :

    <?php
    add_filter( 'mb_settings_pages', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $settings_pages ) {
        $settings_pages[] = [
            'menu_title'  => __( 'Map settings', 'your-text-domain' ),
            'option_name' => 'map',
            'position'    => 80,
            'class'       => 'map_settings',
            'style'       => 'no-boxes',
            'columns'     => 1,
            'network'     => true,
            'icon_url'    => 'dashicons-admin-site',
        ];
    
        return $settings_pages;
    }

    Here are the fields :

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'Countries', 'your-text-domain' ),
            'id'             => 'countries',
            'settings_pages' => ['map_settings'],
            'tabs'           => [
                'global_tab' => [
                    'label' => 'Global',
                    'icon'  => '',
                ],
                'spain_tab' => [
                    'label' => 'Spain',
                    'icon'  => 'admin-appearance',
                ],
            ],
            'fields'         => [
                [
                    'name'   => __( 'Media network', 'your-text-domain' ),
                    'id'     => $prefix . 'global_media_network',
                    'type'   => 'group',
                    'class'  => 'main-group',
                    'fields' => [
                        [
                            'name'   => __( 'Logos', 'your-text-domain' ),
                            'id'     => $prefix . 'global_media_network_images_group',
                            'type'   => 'group',
                            'class'  => 'sub-group',
                            'fields' => [
                                [
                                    'id'               => $prefix . 'global_media_network_group_images',
                                    'type'             => 'image_advanced',
                                    'max_file_uploads' => 4,
                                    'class'            => 'media_network_gallery',
                                ],
                            ],
                        ],
                        [
                            'name'   => __( 'CTA', 'your-text-domain' ),
                            'id'     => $prefix . 'global_media_network_cta',
                            'type'   => 'group',
                            'class'  => 'sub-group',
                            'fields' => [
                                [
                                    'name'    => __( 'CTA wording', 'your-text-domain' ),
                                    'id'      => $prefix . 'global_media_network_cta_wording',
                                    'type'    => 'text',
                                    'columns' => 6,
                                ],
                                [
                                    'name'    => __( 'CTA link', 'your-text-domain' ),
                                    'id'      => $prefix . 'global_media_network_cta_link',
                                    'type'    => 'url',
                                    'columns' => 6,
                                ],
                            ],
                        ],
                    ],
                    'tab'    => 'global_tab',
                ],
                [
                    'name'   => __( 'Media network', 'your-text-domain' ),
                    'id'     => $prefix . 'spain_media_network',
                    'type'   => 'group',
                    'class'  => 'main-group',
                    'fields' => [
                        [
                            'name'   => __( 'Logos', 'your-text-domain' ),
                            'id'     => $prefix . 'spain_media_network_images_group',
                            'type'   => 'group',
                            'class'  => 'sub-group',
                            'fields' => [
                                [
                                    'id'               => $prefix . 'spain_media_network_group_images',
                                    'type'             => 'image_advanced',
                                    'max_file_uploads' => 4,
                                    'class'            => 'media_network_gallery',
                                ],
                            ],
                        ],
                        [
                            'name'   => __( 'CTA', 'your-text-domain' ),
                            'id'     => $prefix . 'global_media_network_cta',
                            'type'   => 'group',
                            'class'  => 'sub-group',
                            'fields' => [
                                [
                                    'name'    => __( 'CTA wording', 'your-text-domain' ),
                                    'id'      => $prefix . 'global_media_network_cta_wording',
                                    'type'    => 'text',
                                    'columns' => 6,
                                ],
                                [
                                    'name'          => __( 'CTA link', 'your-text-domain' ),
                                    'id'            => $prefix . 'global_media_network_cta_link',
                                    'type'          => 'url',
                                    'columns'       => 6,
                                    'tooltip_input' => 'Enter URL (https://....)',
                                ],
                                [
                                    'name'       => __( 'page link', 'your-text-domain' ),
                                    'id'         => $prefix . 'post_tl47lu1cssi',
                                    'type'       => 'post',
                                    'post_type'  => ['page'],
                                    'field_type' => 'select_advanced',
                                ],
                            ],
                        ],
                    ],
                    'tab'    => 'spain_tab',
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    Please can you show me how to display a text field and display all images from a "image advanced" with my configuration ?
    I guess i am missing something :/
    Thanks you very much

    --

    Otherwise I wonder if there a way to use MB views with fields from a setting page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #30582
    Long Nguyen
    Moderator

    Hi Eliott,

    1. You need to get the main group value from the network setting first.
    2. $global_media_network = rwmb_meta( 'global_media_network', ['object_type' => 'network_setting'], 'map');
      

      Follow this documentation https://docs.metabox.io/extensions/mb-settings-page/#getting-field-value

    3. Then access the sub-group and field value based on the ID. Here is the sample code:
    // Display images
    $global_media_network_group_images = $global_media_network['global_media_network_images_group']['global_media_network_group_images'];
    foreach ( $global_media_network_group_images as $image_id ) {
        $image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'large' ) );
        echo '<img src="' . $image['url'] . '">';
    }
    
    // Display wording
    $global_media_network_cta_wording = $global_media_network['global_media_network_cta']['global_media_network_cta_wording'];
    echo $global_media_network_cta_wording;

    Follow this documentation https://docs.metabox.io/extensions/meta-box-group/#getting-sub-field-values

    #30584
    gretch
    Participant

    Maybe my configuration wasn't the easiest one to start with. Thanks to you I think I have now a good base for the following.
    Thank you very much !

    #30735
    gretch
    Participant

    Hi,

    Still on the same settings, the code above works very well but the image advanced field only works on the main site.

    On the others the image source is "unknow" as you can see :
    No images - image advanced (not network main site)

    How can I fix that and display the field across the network ?

    Thank you for your precious help

    #30779
    Long Nguyen
    Moderator

    Hi,

    Thanks for your feedback.

    I will inform the development team to check this issue and get back to you later.

    #30781
    gretch
    Participant

    Hi,

    I guess that means you get the same result on your side.
    I look forward to your return.

    Thank you very much

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