Custom Fields
Re-Envisioned
Support MB Views MB Setting Page param are not rendered in MB views

  • Creator
    Topic
  • #32451
    Resolved sandrinerodrigues
    Participant

    Hello,

    I created a setting page with MB Setting Page, with 3 simple text fields.

    When I created a page through Oxygen 3.9, it perfectly integrated these sitewide custom fields (thanks again for the integration !).

    However, I have a page build in Gutenberg in which I just want to add these 3 text fields.

    So I tried to create a shortcode with MB Views, but cannot display on the front-end these specific fields. It displays site_title, or post_title for example, but not for my custom fields.

    <div>
        <b>Nom du site : {{ site.title }}</b><br>
        {{ post.title }}<br>
        {% set group = attribute( site, 'param-maman-blues' ) %}
    {{ group.nom_du_contact }}
        {% set group = attribute( site, 'param-maman-blues' ) %}
    <img src="{{ group.logo_site.medium.url }}" width="{{ group.logo_site.medium.width }}" height="{{ group.logo_site.medium.height }}" alt="{{ group.logo_site.medium.alt }}">
        
    </div>

    What did I miss ?

    Thank you very much for your support !

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

    Hi,

    Can you please share the code that creates the settings page, custom fields, and some screenshots of your View area?

    #32462
    sandrinerodrigues
    Participant

    Thank you for your reply, here are the differents things :

    php code for setting page :

    <?php
    add_filter( 'mb_settings_pages', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $settings_pages ) {
        $settings_pages[] = [
            'menu_title' => __( 'Infos Maman Blues', 'your-text-domain' ),
            'position'   => 2,
            'capability' => 'edit_posts',
            'icon_url'   => 'dashicons-admin-generic',
        ];
    
        return $settings_pages;
    }

    Code for custom fields

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'Adresse postale', 'your-text-domain' ),
            'id'             => 'informations-de-contact',
            'settings_pages' => ['param-maman-blues'],
            'fields'         => [
                [
                    'name' => __( 'Nom du contact', 'your-text-domain' ),
                    'id'   => $prefix . 'nom_du_contact',
                    'type' => 'text',
                ],
                [
                    'name' => __( 'Rue', 'your-text-domain' ),
                    'id'   => $prefix . 'adresse_postale',
                    'type' => 'text',
                ],
                [
                    'name' => __( 'Code postal / Ville', 'your-text-domain' ),
                    'id'   => $prefix . 'code_postal_ville',
                    'type' => 'text',
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    The MB Views Code :

    <div>
        <b>Nom du site : {{ site.title }}</b><br>
        {{ post.title }}<br>
        {% set group = attribute( site, 'param-maman-blues' ) %}
    {{ group.nom_du_contact }}
        {% set group = attribute( site, 'param-maman-blues' ) %}
    <img src="{{ group.logo_site.medium.url }}" width="{{ group.logo_site.medium.width }}" height="{{ group.logo_site.medium.height }}" alt="{{ group.logo_site.medium.alt }}">
        
    </div>

    Rendered in this page : https://www.preprod.maman-blues.fr/test-metabox/

    Do you have everything you need ?

    #32471
    Long Nguyen
    Moderator

    Hi,

    I think the setting option_name is missed on your settings page. Please check this documentation https://docs.metabox.io/extensions/mb-settings-page/#using-meta-box-builder

    The generated PHP code should be

    add_filter( 'mb_settings_pages', 'your_prefix_function_name' );
    function your_prefix_function_name( $settings_pages ) {
        $settings_pages[] = [
            'menu_title' => __( 'Infos Maman Blues', 'your-text-domain' ),
            'position'   => 2,
            'capability' => 'edit_posts',
            'icon_url'   => 'dashicons-admin-generic',
            'id' => 'param-maman-blues',
            'option_name' => 'param-maman-blues',
        ];
        return $settings_pages;
    }
    #32476
    sandrinerodrigues
    Participant

    Thank you very much, I didn't get that !
    It works fine now 🙂

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