MB Setting Page param are not rendered in MB views
- This topic has 4 replies, 2 voices, and was last updated 3 years, 5 months ago by
sandrinerodrigues.
-
AuthorPosts
-
December 6, 2021 at 4:16 PM #32451
sandrinerodrigues
ParticipantHello,
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 !
December 6, 2021 at 11:11 PM #32459Long Nguyen
ModeratorHi,
Can you please share the code that creates the settings page, custom fields, and some screenshots of your View area?
December 7, 2021 at 12:33 AM #32462sandrinerodrigues
ParticipantThank 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 ?
December 7, 2021 at 10:09 AM #32471Long Nguyen
ModeratorHi,
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-builderThe 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; }
December 7, 2021 at 2:55 PM #32476sandrinerodrigues
ParticipantThank you very much, I didn't get that !
It works fine now 🙂 -
AuthorPosts
- You must be logged in to reply to this topic.