jcchavezs / cmb2-taxonomy

Custom metaboxes for taxonomies
GNU General Public License v2.0
34 stars 8 forks source link

How to create repeatable groupe in taxonomy? #12

Open MicrosoftGovno opened 8 years ago

kristoffeb commented 6 years ago

This is an old issue, but if anyone runs into this, repeatable groups works like this

$box['links'] = [
    'id'           => self::PREFIX . 'links',
    'title'        => __( 'Links', Main::TEXT_DOMAIN ),
    'object_types' => [ 'category' ],
    'show_on_cb'   => [ $this, 'display_box_on_condition' ],
    'fields'       => [
        [
            'id'      => self::PREFIX . 'links_link',
            'type'    => 'group',
            'options' => [
                'group_title'   => __( 'Link', Main::TEXT_DOMAIN ) . ' {#}',
                'add_button'    => __( 'Add another Link', Main::TEXT_DOMAIN ),
                'remove_button' => __( 'Remove Link', Main::TEXT_DOMAIN ),
                'sortable'      => TRUE,
            ],
            'fields'  => [
                [
                    'name'            => __( 'Headline', Main::TEXT_DOMAIN ),
                    'id'              => 'headline',
                    'type'            => 'text_medium',
                    'sanitization_cb' => [ Sanitization_Filters::class, 'strip_dangerous_tags' ],
                ],
                [
                    'name'    => __( 'Image', Main::TEXT_DOMAIN ),
                    'id'      => 'image',
                    'type'    => 'file',
                ],
                [
                    'name'    => __( 'Link', Main::TEXT_DOMAIN ),
                    'id'      => 'link',
                    'type'    => 'text_url',
                ],
            ],
        ],
    ]
];
Mcurly17 commented 5 years ago

@kristoffeb Thanks for your solution, it works like a charm !