Support Forum
Support › MB Settings Page › MB Settings Page 1.3.1, Checkbox List
Have been using free version for quite long time. Need to say nice work. Saves a lot of dev time. Recenlty bought bundle and intresting imediatly have two issues. Where I'm strugglig for while to try to figure by myself. And seems need a help. To make sure did I do correctly or there is a bug to squeeze. 🙂
Here the code. To can test on your side. For me is simple and straightforward.
Began with example form documentatinon with small changes. Just to understand how all this work and beign to build.
add_filter( 'mb_settings_pages', 'swd_options_page' );
function swd_options_page( $settings_pages ) {
$settings_pages[] = array(
'id' => 'swd-theme-settings',
'option_name' => 'swd_theme_settings',
'menu_title' => __( 'Theme Settings', 'swd' ),
'parent' => 'themes.php',
'style' => 'no-boxes',
'columns' => 1,
'tabs' => array(
'content' => __( 'Content Structure', 'swd' ),
'layout' => __( 'Layout', 'swd' ),
'faq' => __( 'FAQ & Help', 'swd' ),
),
);
return $settings_pages;
}
Then goes some settings. For setting page on first tab:
add_filter( 'rwmb_meta_boxes', 'swd_options_meta_boxes' );
function swd_options_meta_boxes( $meta_boxes ) {
$prefix = 'swd_';
$meta_boxes[] = array(
'id' => 'swd_content',
'title' => __( 'Content Structue', 'swd' ),
'settings_pages' => 'swd-theme-settings',
'tab' => 'content',
'fields' => array(
array(
'id' => $prefix . 'sections',
'name' => esc_html__( 'Sections', 'swd' ),
'type' => 'checkbox_list',
'desc' => esc_html__( 'Check or uncheck to enable or disable sections', 'swd' ),
'options' => array(
'gallery' => 'Gallery',
'portfolio' => 'Portfolio',
'services' => 'Services',
'testimonials' => 'Testimonials',
'timeline' => 'Timeline',
'slides' => 'Slides',
'profiles' => 'Profiles',
'brands' => 'Brands',
),
),
),
);
return $meta_boxes;
}
Check box list shows in that setting pge on desired tab. As needed. That part is perfect. Now wehn I check some of them or all of them no matter just to check at least one and save settings. And seems doesn't saves.
The setup is instaled Metabox plugin Version 4.12.2, MB Settings Page Version 1.3.1. Began with totally blank theme. Making from scratch. Implemented sucessfully TGM Plugin Activation that works perfectly. Atm on my local srver is WP multisite working on multiple projects but I think that doesn't affect on this because tried on public stage WP non multiseite and same issue. No other plugins activated.
The other thing is I tried to get data from the settings to make sure might it saves but not set those check boxes. I had similar situations when I builded settings page from scratch that I made mistakes and it saved data but doesn't show in settings page.
$settings = get_option('swd_sections');
print_r( $settings );
die();
Other thing that is bit weird that I tired to get data from example ie head color form the example that for example works and saves only when I want to get data with get_option('heading_color') does get nothing. After began to be sceptical does that get option works at all and tried $settings = get_option('blogname');
and that works perfectly. So I'm bit confuzed. Do I doing somethig wrong or is it bug. If helps I can provide temporary WP log in and FTP access to check this quickly. It is stage site so it is safe to screw up :).
Hi @zac,
Thank you for using our products. I will check the issue you meet and give you the answer ASAP.
About the problem you meet when getting saved data, you should use meta box helper function to get the value, read the docs here.
You can use get_option()
function, but meta box saves all fields data to an entry in wp_options
table, so you can't use get_option( 'field_id' )
. You must use get_option( 'option_name' )
to get an array of all fields data then get the field you want.
Thank you.
Perfect. Thanks for the correction. For check list let me know. No rush for now. I used simple check box for now. That works. But would be more convenient with check list.
Hi zac, I've just fixed the bug with checkbox list. Please update the extension.
Perfect. Wokrs perfectly now. Thanks. Problem solved 😀