Group repeater in settings page

Support MB Settings Page Group repeater in settings pageResolved

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #35523
    admin@dantianhealth.com.au[email protected]
    Participant

    I am struggling and probably out of my depth so could do with a pointer.
    I am using AIO plugin.
    I have a settings page with 3 tabs. On one of them I have created a cloneable group field where the day of the week along with two times can be selected multiple times (ie entering variable Opening Hours).The produced php code looks like:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'Business settings hours', 'your-text-domain' ),
            'id'             => 'business-settings-hours',
            'settings_pages' => ['business-data'],
            'tab'            => 'Hours',
            'fields'         => [
                [
                    'name'              => __( 'Open Hours', 'your-text-domain' ),
                    'id'                => $prefix . 'open_hours',
                    'type'              => 'group',
                    'clone'             => true,
                    'clone_as_multiple' => true,
                    'max_clone'         => 7,
                    'fields'            => [
                        [
                            'name'    => __( 'Day', 'your-text-domain' ),
                            'id'      => $prefix . 'day',
                            'type'    => 'select',
                            'options' => [
                                'Monday'    => __( 'Monday', 'your-text-domain' ),
                                'Tuesday'   => __( 'Tuesday', 'your-text-domain' ),
                                'Wednesday' => __( 'Wednesday', 'your-text-domain' ),
                                'Thursday'  => __( 'Thursday', 'your-text-domain' ),
                                'Friday'    => __( 'Friday', 'your-text-domain' ),
                                'Saturday'  => __( 'Saturday', 'your-text-domain' ),
                                'Sunday'    => __( 'Sunday', 'your-text-domain' ),
                            ],
                        ],
                        [
                            'name' => __( 'Open', 'your-text-domain' ),
                            'id'   => $prefix . 'open',
                            'type' => 'time',
                        ],
                        [
                            'name' => __( 'Close', 'your-text-domain' ),
                            'id'   => $prefix . 'close',
                            'type' => 'time',
                        ],
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    From the settings page, the add more works to create extra, but upon save settings the page resets and the values do not appear to be saved (they do not seem to be able to override settings in relevant entry of wp_options table.
    I then need to print these out in a looped query.
    Can you please point me in the right direction?

    #35530
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can try to follow this tutorial to increase the PHP setting max_input_vars to fix the issue
    https://metabox.io/wordpress-custom-fields-not-saving-increase-max-input-vars/

    Let me know how it goes.

    #35533
    admin@dantianhealth.com.au[email protected]
    Participant

    Thank you. I have tried that without success
    What should I look at next?

    #35541
    Long NguyenLong Nguyen
    Moderator

    Hi,

    I do not see any issue when adding and saving field values with your code. Please try to deactivate all plugins except Meta Box, MB extensions, switch to the standard theme of WordPress, and run only the code above to add the custom fields to the settings page.
    Then re-check this issue.

    #35563
    admin@dantianhealth.com.au[email protected]
    Participant

    I have tried that with no luck. I'm sure I must be doing something wrong but unsure what that must be!

    #35576
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please share your site credentials via this contact form https://metabox.io/contact/
    I will take a closer look.

    #35580
    admin@dantianhealth.com.au[email protected]
    Participant

    COntact form sent. Thanks

    #35607
    Long NguyenLong Nguyen
    Moderator

    Resolved.

    The problem happens due to there are two custom fields that have the same ID on a page.

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