jcchavezs/cmb2-taxonomy

How to create repeatable groupe in taxonomy?

Opened this issue · 2 comments

How to create repeatable groupe in taxonomy?

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',
				],
			],
		],
	]
];

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