Custom Fields
Re-Envisioned
Support General Way to re-use field groups?

  • Creator
    Topic
  • #31261
    alpha.media
    Participant

    Hello,

    I am wondering if there is a way with this plugin or add-ons to define a group of fields and re-use them in another settings box?

    I am building out a settings page that will have multiple meta boxes placed in various locations on it. Some of these boxes will have the exact same settings. I cannot use a repeater field because the order of content needs to be in a certain order.

    Is it possible to define a group of fields and re-use them in multiple places like this?

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

    Hi,

    With the Builder, you can assign a field group (meta box) to more settings pages to re-use the field group. Like this https://share.getcloudapp.com/6quv9bwO

    Using code:

    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    function your_prefix_function_name( $meta_boxes ) {
        $meta_boxes[] = [
            'title'          => __( 'Field Settings page', 'your-text-domain' ),
            'id'             => 'field-settings-page',
            'settings_pages' => ['my-custom-settings', 'my-settings-2'],
            'fields'         => [
                ...
            ],
        ];
        return $meta_boxes;
    }

    Please read more on the documentation https://docs.metabox.io/extensions/mb-settings-page/#creating-settings-fields

    #31296
    alpha.media
    Participant

    Thanks,

    I assume that means though I can't assign it to multiple places on the same settings page?

    For instance, our settings page is to choose modules to be in specific places on the homepage and those modules are the same settings that are re-usable in the specific places they can go. It looks like I can't do that currently.

    #31313
    Long Nguyen
    Moderator

    Hi,

    The field ID (meta key) is associated with the post/page ID or option name (setting page) so it's not possible to use the same field ID in other places on a page.

    You can try to use the cloneable feature to duplicate a field or a group.
    https://docs.metabox.io/cloning-fields/

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